diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index 69c57f2..a1faf88 100644 --- a/README.md +++ b/README.md @@ -1 +1,45 @@ -# path-hints \ No newline at end of file +# 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 + +
page content
+ + +example content
+ + +``` +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). \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7b1c529 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/active_path-path_hints.gemspec b/active_path-path_hints.gemspec new file mode 100644 index 0000000..f0d9ecc --- /dev/null +++ b/active_path-path_hints.gemspec @@ -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 = 'rtulino@gmail.com' + 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 \ No newline at end of file diff --git a/lib/active_path/path_hints.rb b/lib/active_path/path_hints.rb new file mode 100644 index 0000000..38931cd --- /dev/null +++ b/lib/active_path/path_hints.rb @@ -0,0 +1 @@ +require 'active_path/path_hints/engine' \ No newline at end of file diff --git a/lib/active_path/path_hints/engine.rb b/lib/active_path/path_hints/engine.rb new file mode 100644 index 0000000..5ffc715 --- /dev/null +++ b/lib/active_path/path_hints/engine.rb @@ -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 diff --git a/lib/active_path/path_hints/subscriber.rb b/lib/active_path/path_hints/subscriber.rb new file mode 100644 index 0000000..a8a1299 --- /dev/null +++ b/lib/active_path/path_hints/subscriber.rb @@ -0,0 +1,23 @@ +require 'active_path/subscribers/subscriber' +module ActivePath + module PathHints + class Subscriber < Subscribers::Subscriber + def perform + buffer.prepend("".html_safe) + buffer.concat("".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 \ No newline at end of file diff --git a/lib/active_path/path_hints/version.rb b/lib/active_path/path_hints/version.rb new file mode 100644 index 0000000..9d5d7f9 --- /dev/null +++ b/lib/active_path/path_hints/version.rb @@ -0,0 +1,5 @@ +module ActivePath + module PathHints + VERSION = '0.1.0' + end +end \ No newline at end of file