Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan tulino committed Apr 30, 2018
1 parent 1643c6f commit 7593f4e
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# path-hints
# ActivePath Path Hints:

Path hints for your Rails 5 partials.

## Installation

Add to your Gemfile:

```ruby
gem 'active_path-path_hints'
```

Add the initializer `config/initializers/active_path.rb` and enable `ActivePath`:

```ruby

ActivePath.configure do |config|

config.enabled = true

end

```

**Path hints:** (use in development only)


```ruby

config.path_hints = true

```

HTML comments are added before and after each partial. Here is sample output:

```html
<!-- start pages/content -->
<p>page content</p>
<!-- end pages/content -->
<!-- start example/test -->
<p>example content</p>
<!-- end example/test -->

```
Feel free to [submit issues](https://github.com/active-path/path-hints/issues) or [help make it better](https://github.com/active-path/path-hints/pulls).
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env rake

$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'active_path/path_hints/version'

desc "Release version #{ActivePath::PathHints::VERSION} of the gem"
task :release do

system "git tag -a v#{ActivePath::PathHints::VERSION} -m 'Tagging #{ActivePath::PathHints::VERSION}'"
system 'git push --tags'

system "gem build active_path-path_hints.gemspec"
system "gem push active_path-path_hints#{ActivePath::PathHints::VERSION}.gem"
system "rm active_path-path_hints#{ActivePath::PathHints::VERSION}.gem"
end
17 changes: 17 additions & 0 deletions active_path-path_hints.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$:.push File.expand_path('../lib', __FILE__)
require 'active_path/path_hints/version'

Gem::Specification.new do |s|
s.name = 'active_path-path_hints'
s.version = ActivePath::PathHints::VERSION
s.date = '2018-04-28'
s.summary = "ActivePath Path Hints"
s.description = "Path hints for your Rails 5 partials"
s.authors = ["Ryan Tulino"]
s.email = '[email protected]'
s.files = `git ls-files`.split("\n")
s.homepage = 'http://rubygems.org/gems/active_path-path_hints'
s.required_ruby_version = '>= 2.2.0'
s.add_dependency 'rails', '~> 5'
s.add_dependency 'active_path', '~> 0.1.0'
end
1 change: 1 addition & 0 deletions lib/active_path/path_hints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'active_path/path_hints/engine'
14 changes: 14 additions & 0 deletions lib/active_path/path_hints/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_path/path_hints/subscriber'
module ActivePath
module PathHints
class Engine < Rails::Engine
isolate_namespace ActivePath::PathHints

config.after_initialize do
if ActivePath.config.path_hints
ActiveSupport::Notifications.subscribe(:render_partial, Subscriber.new)
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/active_path/path_hints/subscriber.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'active_path/subscribers/subscriber'
module ActivePath
module PathHints
class Subscriber < Subscribers::Subscriber
def perform
buffer.prepend("<!-- start #{partial}#{with_local_variables.to_s} --!>".html_safe)
buffer.concat("<!-- end #{partial} --!>".html_safe)
end

private

def with_local_variables
if options.is_a?(Hash)
variables = options[:locals].map do |k,v|
count = (" (#{v.count})" if v.is_a?(Array)).to_s
"#{k} => #{v.class}#{count}"
end
"\nwith local variables: #{JSON.pretty_generate(variables)}"
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/active_path/path_hints/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ActivePath
module PathHints
VERSION = '0.1.0'
end
end

0 comments on commit 7593f4e

Please sign in to comment.