Skip to content
This repository
Browse code

Add annotation to haml and slim template.

  • Loading branch information...
commit 8f61df0bcd0e84f26c6c41b98eeb2f7bb8d5ca4b 1 parent 885a599
Kazimierz Kiełkowicz kielkowicz authored
4 railties/lib/rails/source_annotation_extractor.rb
@@ -69,6 +69,10 @@ def find_in(dir)
69 69 results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
70 70 elsif item =~ /\.erb$/
71 71 results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
  72 + elsif item =~ /\.haml$/
  73 + results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/))
  74 + elsif item =~ /\.slim$/
  75 + results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/))
72 76 end
73 77 end
74 78
42 railties/test/railties/rake_tasks_test.rb
... ... @@ -0,0 +1,42 @@
  1 +require "isolation/abstract_unit"
  2 +
  3 +module RailtiesTest
  4 + class RakeNotesTest < Test::Unit::TestCase
  5 + def setup
  6 + build_app
  7 + require "rails/all"
  8 + end
  9 +
  10 + def teardown
  11 + teardown_app
  12 + end
  13 +
  14 + test 'notes' do
  15 + app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
  16 + app_file "app/views/home/index.html.haml", "-# TODO: note in haml"
  17 + app_file "app/views/home/index.html.slim", "/ TODO: note in slim"
  18 +
  19 + boot_rails
  20 + require 'rake'
  21 + require 'rdoc/task'
  22 + require 'rake/testtask'
  23 +
  24 + Rails.application.load_tasks
  25 +
  26 + Dir.chdir(app_path) do
  27 + output = `bundle exec rake notes`
  28 +
  29 + assert_match /note in erb/, output
  30 + assert_match /note in haml/, output
  31 + assert_match /note in slim/, output
  32 + end
  33 +
  34 + end
  35 +
  36 + private
  37 + def boot_rails
  38 + super
  39 + require "#{app_path}/config/environment"
  40 + end
  41 + end
  42 +end

1 comment on commit 8f61df0

Gabriel Sobrinho

Maybe this should be available as hook for others template engines :)

Please sign in to comment.
Something went wrong with that request. Please try again.