deface 1.0.0.rc3 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a72a852dcfe7cec6de674b4596fe8cea3f350937
4
+ data.tar.gz: bf66b21acd0eb5da511d76c8c785d47cb57004ff
5
+ SHA512:
6
+ metadata.gz: 5bad01645ba75cdb71f60615ba287993c92eb5fa8b302384e9343abca8535eac8436baba79e65f72071f2f4252e35d67bb623dc13e4e4dedecb25d7312c90497
7
+ data.tar.gz: da65449721be0849dbb1cfe001af8cd591e74dc3d87e2d767d4dd302e585d15be48381a78de5643f32d2e562a780d909f5662abb088abbaac4d10baab5fea096
@@ -0,0 +1,4 @@
1
+ ## 1.0.0.rc4 (2013-09-04)
2
+
3
+ * [BREAKING CHANGE] ERB blocks are no longer converted into <code erb-loud|erb-silent>, now they are <erb loud|silent> [jhawthorn]
4
+ * Lots of other changes too numerous to list here in the first changelog entry, will get better going forward :)
data/README.markdown CHANGED
@@ -144,7 +144,7 @@ Removes any ERB block containing the string `helper_method` in the `posts/new.ht
144
144
  ```ruby
145
145
  Deface::Override.new(:virtual_path => "posts/new",
146
146
  :name => "example-4",
147
- :remove => "code[erb-loud]:contains('helper_method')",
147
+ :remove => "erb[loud]:contains('helper_method')",
148
148
  :original => "<%= helper_method %>")
149
149
  ```
150
150
 
@@ -171,8 +171,8 @@ Remove an entire ERB if statement (and all it's contents) in the 'admin/products
171
171
  ```ruby
172
172
  Deface::Override.new(:virtual_path => 'admin/products/index',
173
173
  :name => "remove_if_statement",
174
- :remove => "code[erb-silent]:contains('if @product.sold?')",
175
- :closing_selector => "code[erb-silent]:contains('end')"
174
+ :remove => "erb[silent]:contains('if @product.sold?')",
175
+ :closing_selector => "erb[silent]:contains('end')"
176
176
  ```
177
177
 
178
178
  ### Scope
@@ -244,9 +244,12 @@ and including haml source:
244
244
  You can include all the additional options you can normally use when defining a Deface::Override manually, a more complex example:
245
245
 
246
246
  ```html
247
- <!-- replace_contents 'h1' closing_selector 'div#intro' disabled -->
247
+ <!-- replace_contents 'h1' closing_selector 'div#intro'
248
+ sequence :before => 'my_other_override'
249
+ disabled -->
248
250
  <p>This is a complicated example</p>
249
251
  ```
252
+ Note options requiring a hash should be on a separate line.
250
253
 
251
254
  #### Disabled / Enabled
252
255
 
@@ -351,7 +354,7 @@ Deface temporarily converts ERB files into a pseudo HTML markup that can be pars
351
354
  becomes:
352
355
 
353
356
  ```html
354
- <code erb-loud> some ruby code </code>
357
+ <erb loud> some ruby code </erb>
355
358
  ```
356
359
 
357
360
  and
@@ -363,7 +366,7 @@ and
363
366
  becomes:
364
367
 
365
368
  ```html
366
- <code erb-silent> other ruby code </code>
369
+ <erb silent> other ruby code </erb>
367
370
  ```
368
371
 
369
372
  ERB that is contained inside a HTML tag definition is converted slightly differently to ensure a valid HTML document that Nokogiri can parse:
data/deface.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "deface"
3
- s.version = "1.0.0.rc3"
3
+ s.version = "1.0.0.rc4"
4
4
 
5
5
  s.authors = ["Brian D Quinn"]
6
6
  s.description = "Deface is a library that allows you to customize ERB, Haml and Slim views in a Rails application without editing the underlying view."
7
7
  s.email = "brian@spreecommerce.com"
8
8
  s.extra_rdoc_files = [
9
- "README.markdown"
9
+ "README.markdown", "CHANGELOG.markdown"
10
10
  ]
11
11
  s.files = `git ls-files`.split("\n")
12
12
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -6,10 +6,10 @@ module Deface
6
6
  end
7
7
 
8
8
  def original_placeholders
9
- @original_placeholders ||= source_element.css("code:contains('render_original')")
9
+ @original_placeholders ||= source_element.css("erb:contains('render_original')")
10
10
  raise(DefaceError, "The surround action couldn't find <%= render_original %> in your template") unless @original_placeholders.first
11
11
  @original_placeholders
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -32,6 +32,12 @@ module Deface
32
32
 
33
33
  if log
34
34
  Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'")
35
+
36
+ # temporarily check and notify on use of old selector styles.
37
+ #
38
+ if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/)
39
+ Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Override '#{override.name}' may be using an invalid selector of '#{override.selector}', <code erb-loud|silent> tags are now <erb loud|silent>"
40
+ end
35
41
  end
36
42
 
37
43
  if matches.empty?
data/lib/deface/parser.rb CHANGED
@@ -34,13 +34,13 @@ module Deface
34
34
  end
35
35
 
36
36
  #replaces all <% %> not inside opening html tags
37
- replacements = [ {"<%=" => "<code erb-loud>"},
38
- {"<%" => "<code erb-silent>"},
39
- {"%>" => "</code>"} ]
37
+ replacements = [ {"<%=" => "<erb loud>"},
38
+ {"<%" => "<erb silent>"},
39
+ {"%>" => "</erb>"} ]
40
40
 
41
41
  replacements.each{ |h| h.each { |replace, with| source.gsub! replace, with } }
42
42
 
43
- source.scan(/(<code.*?>)((?:(?!<\/code>)[\s\S])*)(<\/code>)/).each do |match|
43
+ source.scan(/(<erb.*?>)((?:(?!<\/erb>)[\s\S])*)(<\/erb>)/).each do |match|
44
44
  source.sub!("#{match[0]}#{match[1]}#{match[2]}") { |m| m = "#{match[0]}#{CGI.escapeHTML(match[1])}#{match[2]}" }
45
45
  end
46
46
 
@@ -50,11 +50,11 @@ module Deface
50
50
  # undoes ERB markup generated by Deface::Parser::ERB
51
51
  #
52
52
  def self.undo_erb_markup!(source)
53
- replacements = [ {"<code erb-silent>" => '<%'},
54
- {"<code erb-silent=\"\">" => '<%'},
55
- {"<code erb-loud>" => '<%='},
56
- {"<code erb-loud=\"\">" => '<%='},
57
- {"</code>" => '%>'}]
53
+ replacements = [ {"<erb silent>" => '<%'},
54
+ {"<erb silent=\"\">" => '<%'},
55
+ {"<erb loud>" => '<%='},
56
+ {"<erb loud=\"\">" => '<%='},
57
+ {"</erb>" => '%>'}]
58
58
 
59
59
  replacements.each{ |h| h.each { |replace, with| source.gsub! replace, with } }
60
60
 
@@ -31,7 +31,7 @@ module Deface
31
31
 
32
32
  describe "with a single :copy using :start and :end" do
33
33
  before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_before => "h1",
34
- :copy => {:start => "code:contains('if true')", :end => "code:contains('end')"}) }
34
+ :copy => {:start => "erb:contains('if true')", :end => "erb:contains('end')"}) }
35
35
  let(:source) { "<h1>World</h1><% if true %><p>True that!</p><% end %><p>Hello</p>" }
36
36
 
37
37
 
@@ -52,7 +52,7 @@ module Deface
52
52
 
53
53
  describe "with a single :cut using :start and :end" do
54
54
  before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1",
55
- :cut => {:start => "code:contains('if true')", :end => "code:contains('end')"}) }
55
+ :cut => {:start => "erb:contains('if true')", :end => "erb:contains('end')"}) }
56
56
  let(:source) { "<h1>World</h1><% if true %><p>True that!</p><% end %><p>Hello</p>" }
57
57
 
58
58
 
@@ -37,7 +37,7 @@ describe Deface::DSL::Context do
37
37
  it 'should generate a warning if two action values are specified' do
38
38
  subject.insert_top('selector')
39
39
 
40
- logger = mock('logger')
40
+ logger = double('logger')
41
41
  Rails.should_receive(:logger).and_return(logger)
42
42
  logger.should_receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple action methods have been called. The last one will be used.")
43
43
 
@@ -67,7 +67,7 @@ describe Deface::DSL::Context do
67
67
  it 'should generate a warning if two sources are specified' do
68
68
  subject.partial('partial name')
69
69
 
70
- logger = mock('logger')
70
+ logger = double('logger')
71
71
  Rails.should_receive(:logger).and_return(logger)
72
72
  logger.should_receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple source methods have been called. The last one will be used.")
73
73
 
@@ -6,7 +6,7 @@ describe Deface::DSL::Loader do
6
6
  context '.load' do
7
7
  context 'extension check' do
8
8
  it 'should succeed if file ends with .deface' do
9
- file = mock('deface file')
9
+ file = double('deface file')
10
10
  filename = 'app/overrides/example_name.deface'
11
11
 
12
12
  lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
@@ -14,7 +14,7 @@ describe Deface::DSL::Loader do
14
14
  end
15
15
 
16
16
  it 'should succeed if file ends with .html.erb.deface' do
17
- file = mock('deface file')
17
+ file = double('deface file')
18
18
  filename = 'app/overrides/example_name.html.erb.deface'
19
19
 
20
20
  lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
@@ -22,7 +22,7 @@ describe Deface::DSL::Loader do
22
22
  end
23
23
 
24
24
  it 'should succeed if file ends with .html.haml.deface' do
25
- file = mock('deface file')
25
+ file = double('deface file')
26
26
  filename = 'app/overrides/example_name.html.haml.deface'
27
27
 
28
28
  lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
@@ -30,7 +30,7 @@ describe Deface::DSL::Loader do
30
30
  end
31
31
 
32
32
  it 'should succeed if file ends with .html.slim.deface' do
33
- file = mock('deface file')
33
+ file = double('deface file')
34
34
  filename = 'app/overrides/example_name.html.slim.deface'
35
35
 
36
36
  lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
@@ -38,7 +38,7 @@ describe Deface::DSL::Loader do
38
38
  end
39
39
 
40
40
  it 'should fail if file ends with .blargh.deface' do
41
- file = mock('deface file')
41
+ file = double('deface file')
42
42
  filename = 'app/overrides/example_name.blargh.deface'
43
43
 
44
44
  lambda { Deface::DSL::Loader.load(filename) }.should raise_error(
@@ -46,7 +46,7 @@ describe Deface::DSL::Loader do
46
46
  end
47
47
 
48
48
  it "should suceed if parent directory has a dot(.) in it's name" do
49
- file = mock('deface file')
49
+ file = double('deface file')
50
50
  filename = 'app/overrides/parent.dir.with.dot/example_name.html.haml.deface'
51
51
 
52
52
  lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
@@ -55,7 +55,7 @@ describe Deface::DSL::Loader do
55
55
  end
56
56
 
57
57
  it 'should fail if .html.erb.deface file is in the root of app/overrides' do
58
- file = mock('html/erb/deface file')
58
+ file = double('html/erb/deface file')
59
59
  filename = 'app/overrides/example_name.html.erb.deface'
60
60
 
61
61
  lambda { Deface::DSL::Loader.load(filename) }.should raise_error(
@@ -63,16 +63,16 @@ describe Deface::DSL::Loader do
63
63
  end
64
64
 
65
65
  it 'should set the virtual_path for a .deface file in a directory below overrides' do
66
- file = mock('deface file')
66
+ file = double('deface file')
67
67
  filename = 'app/overrides/path/to/view/example_name.deface'
68
68
  File.should_receive(:open).with(filename).and_yield(file)
69
69
 
70
70
  override_name = 'example_name'
71
- context = mock('dsl context')
71
+ context = double('dsl context')
72
72
  Deface::DSL::Context.should_receive(:new).with(override_name).
73
73
  and_return(context)
74
74
 
75
- file_contents = mock('file contents')
75
+ file_contents = double('file contents')
76
76
  file.should_receive(:read).and_return(file_contents)
77
77
 
78
78
  context.should_receive(:virtual_path).with('path/to/view').ordered
@@ -83,16 +83,16 @@ describe Deface::DSL::Loader do
83
83
  end
84
84
 
85
85
  it 'should set the virtual_path for a .html.erb.deface file in a directory below overrides' do
86
- file = mock('html/erb/deface file')
86
+ file = double('html/erb/deface file')
87
87
  filename = 'app/overrides/path/to/view/example_name.html.erb.deface'
88
88
  File.should_receive(:open).with(filename).and_yield(file)
89
89
 
90
90
  override_name = 'example_name'
91
- context = mock('dsl context')
91
+ context = double('dsl context')
92
92
  Deface::DSL::Context.should_receive(:new).with(override_name).
93
93
  and_return(context)
94
94
 
95
- file_contents = mock('file contents')
95
+ file_contents = double('file contents')
96
96
  file.should_receive(:read).and_return(file_contents)
97
97
 
98
98
  Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_erb).
@@ -108,16 +108,16 @@ describe Deface::DSL::Loader do
108
108
  end
109
109
 
110
110
  it 'should set the virtual_path for a .html.haml.deface file in a directory below overrides' do
111
- file = mock('html/haml/deface file')
111
+ file = double('html/haml/deface file')
112
112
  filename = 'app/overrides/path/to/view/example_name.html.haml.deface'
113
113
  File.should_receive(:open).with(filename).and_yield(file)
114
114
 
115
115
  override_name = 'example_name'
116
- context = mock('dsl context')
116
+ context = double('dsl context')
117
117
  Deface::DSL::Context.should_receive(:new).with(override_name).
118
118
  and_return(context)
119
119
 
120
- file_contents = mock('file contents')
120
+ file_contents = double('file contents')
121
121
  file.should_receive(:read).and_return(file_contents)
122
122
 
123
123
  Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_haml).
@@ -133,16 +133,16 @@ describe Deface::DSL::Loader do
133
133
  end
134
134
 
135
135
  it 'should set the virtual_path for a .html.slim.deface file in a directory below overrides' do
136
- file = mock('html/slim/deface file')
136
+ file = double('html/slim/deface file')
137
137
  filename = 'app/overrides/path/to/view/example_name.html.slim.deface'
138
138
  File.should_receive(:open).with(filename).and_yield(file)
139
139
 
140
140
  override_name = 'example_name'
141
- context = mock('dsl context')
141
+ context = double('dsl context')
142
142
  Deface::DSL::Context.should_receive(:new).with(override_name).
143
143
  and_return(context)
144
144
 
145
- file_contents = mock('file contents')
145
+ file_contents = double('file contents')
146
146
  file.should_receive(:read).and_return(file_contents)
147
147
 
148
148
  Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_slim).
@@ -54,7 +54,7 @@ module Deface
54
54
  end
55
55
 
56
56
  it "should enumerate_and_load nil when railtie has no app/overrides path set" do
57
- Rails.application.stub_chain :railties, railties_collection_accessor => [mock('railtie', :root => "/some/path")]
57
+ Rails.application.stub_chain :railties, railties_collection_accessor => [double('railtie', :root => "/some/path")]
58
58
 
59
59
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
60
60
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, "/some/path")
@@ -62,7 +62,7 @@ module Deface
62
62
  end
63
63
 
64
64
  it "should enumerate_and_load path when railtie has app/overrides path set" do
65
- Rails.application.stub_chain :railties, railties_collection_accessor => [ mock('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
65
+ Rails.application.stub_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
66
66
 
67
67
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
68
68
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , "/some/path")
@@ -70,7 +70,7 @@ module Deface
70
70
  end
71
71
 
72
72
  it "should enumerate_and_load railties first, followed by the application iteslf" do
73
- Rails.application.stub_chain :railties, railties_collection_accessor => [ mock('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
73
+ Rails.application.stub_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
74
74
 
75
75
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , "/some/path").ordered
76
76
  Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root).ordered
@@ -78,7 +78,7 @@ module Deface
78
78
  end
79
79
 
80
80
  it "should ignore railtie with no root" do
81
- railtie = mock('railtie')
81
+ railtie = double('railtie')
82
82
  Rails.application.stub_chain :railties, railties_collection_accessor => [railtie]
83
83
 
84
84
  railtie.should_receive(:respond_to?).with(:root)
@@ -96,7 +96,7 @@ module Deface
96
96
 
97
97
  describe 'load_overrides' do
98
98
  let(:assets_path) { Pathname.new(File.join(File.dirname(__FILE__), '..', "assets")) }
99
- let(:engine) { mock('railtie', :root => assets_path, :class => "DummyEngine", :paths => {"app/overrides" => ["dummy_engine"]}) }
99
+ let(:engine) { double('railtie', :root => assets_path, :class => "DummyEngine", :paths => {"app/overrides" => ["dummy_engine"]}) }
100
100
  before { Rails.application.stub(:class => 'RailsAppl') }
101
101
 
102
102
  it "should keep a reference to which railtie/app defined the override" do
@@ -38,9 +38,9 @@ module Deface
38
38
  @original.original_source.should be_an_instance_of Nokogiri::HTML::DocumentFragment
39
39
 
40
40
  if RUBY_PLATFORM == 'java'
41
- @original.original_source.to_s.should == "<p><code erb-loud=\"\"> something </code></p>"
41
+ @original.original_source.to_s.should == "<p><erb loud=\"\"> something </erb></p>"
42
42
  else
43
- @original.original_source.to_s.should == "<p><code erb-loud> something </code></p>"
43
+ @original.original_source.to_s.should == "<p><erb loud> something </erb></p>"
44
44
  end
45
45
  end
46
46
  end
@@ -64,11 +64,11 @@ module Deface
64
64
 
65
65
  it "should return true when input contains similar (ignoring whitespace)" do
66
66
  if RUBY_PLATFORM == 'java'
67
- @original.validate_original("<p><code erb-loud=\"\"> something </code></p>").should be_true
68
- @original.validate_original("<p><code erb-loud=\"\">something\n</code> </p>").should be_true
67
+ @original.validate_original("<p><erb loud=\"\"> something </erb></p>").should be_true
68
+ @original.validate_original("<p><erb loud=\"\">something\n</erb> </p>").should be_true
69
69
  else
70
- @original.validate_original("<p><code erb-loud> something </code></p>").should be_true
71
- @original.validate_original("<p><code erb-loud>something\n</code> </p>").should be_true
70
+ @original.validate_original("<p><erb loud> something </erb></p>").should be_true
71
+ @original.validate_original("<p><erb loud>something\n</erb> </p>").should be_true
72
72
  end
73
73
  end
74
74
 
@@ -117,11 +117,11 @@ module Deface
117
117
 
118
118
  before(:each) do
119
119
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1",
120
- :haml => %q{%strong{:class => "code", :id => "message"}= 'Hello, World!'})
120
+ :haml => %q{%strong{:class => "erb", :id => "message"}= 'Hello, World!'})
121
121
  end
122
122
 
123
123
  it "should return erb converted from haml as source" do
124
- @override.source.should == "<strong class='code' id='message'><%= 'Hello, World!' %>\n</strong>\n"
124
+ @override.source.should == "<strong class='erb' id='message'><%= 'Hello, World!' %>\n</strong>\n"
125
125
 
126
126
  @override.source_argument.should == :haml
127
127
  end
@@ -131,11 +131,11 @@ module Deface
131
131
 
132
132
  before(:each) do
133
133
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1",
134
- :slim => %q{strong class="code" id="message"= 'Hello, World!'})
134
+ :slim => %q{strong class="erb" id="message"= 'Hello, World!'})
135
135
  end
136
136
 
137
137
  it "should return erb converted from slim as source" do
138
- @override.source.should == "<strong class=\"code\" id=\"message\"><%= ::Temple::Utils.escape_html_safe(('Hello, World!')) %><%\n%></strong>"
138
+ @override.source.should == "<strong class=\"erb\" id=\"message\"><%= ::Temple::Utils.escape_html_safe(('Hello, World!')) %><%\n%></strong>"
139
139
 
140
140
  @override.source_argument.should == :slim
141
141
  end
@@ -189,9 +189,9 @@ module Deface
189
189
  @override.source
190
190
 
191
191
  if RUBY_PLATFORM == 'java'
192
- parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><code erb-loud=\"\"> some_method </code></div>"
192
+ parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><erb loud=\"\"> some_method </erb></div>"
193
193
  else
194
- parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><code erb-loud> some_method </code></div>"
194
+ parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><erb loud> some_method </erb></div>"
195
195
  end
196
196
 
197
197
  @override.source_argument.should == :copy
@@ -202,7 +202,7 @@ module Deface
202
202
  end
203
203
 
204
204
  it "should return unescaped content for source document" do
205
- @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :copy => "code[erb-loud]:contains('some_method')")
205
+ @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :copy => "erb[loud]:contains('some_method')")
206
206
  @override.stub(:parsed_document).and_return(parsed)
207
207
  @override.source.should == "<%= some_method %>"
208
208
  end
@@ -215,7 +215,7 @@ module Deface
215
215
 
216
216
  before(:each) do
217
217
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1",
218
- :copy => {:start => "code:contains('if true')", :end => "code:contains('end')"})
218
+ :copy => {:start => "erb:contains('if true')", :end => "erb:contains('end')"})
219
219
 
220
220
  @override.stub(:parsed_document).and_return(parsed)
221
221
  end
@@ -224,9 +224,9 @@ module Deface
224
224
  @override.source
225
225
 
226
226
  if RUBY_PLATFORM == 'java'
227
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><code erb-silent=\"\"> if true </code><p>True that!</p><code erb-silent=\"\"> end </code><p>Hello</p>"
227
+ parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb silent=\"\"> if true </erb><p>True that!</p><erb silent=\"\"> end </erb><p>Hello</p>"
228
228
  else
229
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><code erb-silent> if true </code><p>True that!</p><code erb-silent> end </code><p>Hello</p>"
229
+ parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb silent> if true </erb><p>True that!</p><erb silent> end </erb><p>Hello</p>"
230
230
  end
231
231
 
232
232
  @override.source_argument.should == :copy
@@ -247,9 +247,9 @@ module Deface
247
247
  it "should remove cut element from original parsed source" do
248
248
  @override.source
249
249
  if RUBY_PLATFORM == 'java'
250
- parsed.to_s.gsub(/\n/,'').should == "<div><code erb-loud=\"\"> some_method </code></div>"
250
+ parsed.to_s.gsub(/\n/,'').should == "<div><erb loud=\"\"> some_method </erb></div>"
251
251
  else
252
- parsed.to_s.gsub(/\n/,'').should == "<div><code erb-loud> some_method </code></div>"
252
+ parsed.to_s.gsub(/\n/,'').should == "<div><erb loud> some_method </erb></div>"
253
253
  end
254
254
 
255
255
  @override.source_argument.should == :cut
@@ -260,7 +260,7 @@ module Deface
260
260
  end
261
261
 
262
262
  it "should return unescaped content for source document" do
263
- @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :cut => "code[erb-loud]:contains('some_method')")
263
+ @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :cut => "erb[loud]:contains('some_method')")
264
264
  @override.stub(:parsed_document).and_return(parsed)
265
265
  @override.source.should == "<%= some_method %>"
266
266
  end
@@ -274,7 +274,7 @@ module Deface
274
274
 
275
275
  before(:each) do
276
276
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1",
277
- :cut => {:start => "code:contains('if true')", :end => "code:contains('end')"})
277
+ :cut => {:start => "erb:contains('if true')", :end => "erb:contains('end')"})
278
278
 
279
279
  @override.stub(:parsed_document).and_return(parsed)
280
280
  end
@@ -282,9 +282,9 @@ module Deface
282
282
  it "should remove cut element from original parsed source" do
283
283
  @override.source
284
284
  if RUBY_PLATFORM == 'java'
285
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><code erb-loud=\"\"> hello </code>"
285
+ parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb loud=\"\"> hello </erb>"
286
286
  else
287
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><code erb-loud> hello </code>"
287
+ parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb loud> hello </erb>"
288
288
  end
289
289
 
290
290
  @override.source_argument.should == :cut
@@ -342,12 +342,12 @@ module Deface
342
342
  @override.source_element.should be_an_instance_of Nokogiri::HTML::DocumentFragment
343
343
 
344
344
  if RUBY_PLATFORM == 'java'
345
- source = "<code erb-loud=\"\"> method :opt =&gt; 'x' &amp; 'y' </code>"
345
+ source = "<erb loud=\"\"> method :opt =&gt; 'x' &amp; 'y' </erb>"
346
346
  @override.source_element.to_s.should == source
347
347
  #do it twice to ensure it doesn't change as it's destructive
348
348
  @override.source_element.to_s.should == source
349
349
  else
350
- source = "<code erb-loud> method :opt =&gt; 'x' &amp; 'y' </code>"
350
+ source = "<erb loud> method :opt =&gt; 'x' &amp; 'y' </erb>"
351
351
  @override.source_element.to_s.should == source
352
352
  #do it twice to ensure it doesn't change as it's destructive
353
353
  @override.source_element.to_s.should == source
@@ -497,7 +497,7 @@ module Deface
497
497
  Deface::Override.all.clear
498
498
 
499
499
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
500
- @second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "p", :text => "<pre>this is code?</pre>")
500
+ @second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "p", :text => "<pre>this is erb?</pre>")
501
501
 
502
502
  @digest = Deface::Override.digest(:virtual_path => "posts/index")
503
503
  end
@@ -513,7 +513,7 @@ module Deface
513
513
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
514
514
  Deface::Override.digest(:virtual_path => "posts/index").should == @digest
515
515
 
516
- @second = Deface::Override.new(:virtual_path => "posts/index", :name => "2nd", :insert_after => "p", :text => "<pre>this is code?</pre>")
516
+ @second = Deface::Override.new(:virtual_path => "posts/index", :name => "2nd", :insert_after => "p", :text => "<pre>this is erb?</pre>")
517
517
  Deface::Override.digest(:virtual_path => "posts/index").should_not == @digest
518
518
  end
519
519
 
@@ -58,6 +58,20 @@ module Deface
58
58
  end
59
59
  end
60
60
 
61
+ # Regression test for #84, #100
62
+ it "should parse html document with erb in the head" do
63
+ parsed = Deface::Parser.convert("<html><head><%= method_name %></head><body></body></html>")
64
+ parsed.should be_an_instance_of(Nokogiri::HTML::Document)
65
+ parsed = parsed.to_s.split("\n")
66
+
67
+ if RUBY_PLATFORM == 'java'
68
+ parsed.should == ["<html><head><erb loud=\"\"> method_name </erb></head><body></body></html>"]
69
+ else
70
+ parsed = parsed[1..-1]
71
+ parsed.should == "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<erb loud> method_name </erb>\n</head>\n<body></body>\n</html>".split("\n")
72
+ end
73
+ end
74
+
61
75
  it "should parse body tag" do
62
76
  tag = Deface::Parser.convert("<body id=\"body\" <%= something %>>test</body>")
63
77
  tag.should be_an_instance_of(Nokogiri::XML::Element)
@@ -68,14 +82,14 @@ module Deface
68
82
 
69
83
  it "should convert <% ... %>" do
70
84
  tag = Deface::Parser.convert("<% method_name %>")
71
- tag = tag.css('code').first
72
- tag.attributes['erb-silent'].value.should eq ''
85
+ tag = tag.css('erb').first
86
+ tag.attributes['silent'].value.should eq ''
73
87
  end
74
88
 
75
89
  it "should convert <%= ... %>" do
76
90
  tag = Deface::Parser.convert("<%= method_name %>")
77
- tag = tag.css('code').first
78
- tag.attributes['erb-loud'].value.should eq ''
91
+ tag = tag.css('erb').first
92
+ tag.attributes['loud'].value.should eq ''
79
93
  end
80
94
 
81
95
  it "should convert first <% ... %> inside html tag" do
@@ -129,23 +143,23 @@ module Deface
129
143
  tag.text.should eq 'A Link'
130
144
  end
131
145
 
132
- it "should escape contents code tags" do
146
+ it "should escape contents erb tags" do
133
147
  tag = Deface::Parser.convert("<% method_name :key => 'value' %>")
134
- tag = tag.css('code').first
135
- tag.attributes.key?('erb-silent').should be_true
148
+ tag = tag.css('erb').first
149
+ tag.attributes.key?('silent').should be_true
136
150
  tag.text.should eq " method_name :key => 'value' "
137
151
  end
138
152
 
139
- it "should handle round brackets in code tags" do
153
+ it "should handle round brackets in erb tags" do
140
154
  # commented out line below will fail as : adjacent to ( causes Nokogiri parser issue on jruby
141
155
  tag = Deface::Parser.convert("<% method_name(:key => 'value') %>")
142
- tag = tag.css('code').first
143
- tag.attributes.key?('erb-silent').should be_true
156
+ tag = tag.css('erb').first
157
+ tag.attributes.key?('silent').should be_true
144
158
  tag.text.should eq " method_name(:key => 'value') "
145
159
 
146
160
  tag = Deface::Parser.convert("<% method_name( :key => 'value' ) %>")
147
- tag = tag.css('code').first
148
- tag.attributes.key?('erb-silent').should be_true
161
+ tag = tag.css('erb').first
162
+ tag.attributes.key?('silent').should be_true
149
163
  tag.text.should eq " method_name( :key => 'value' ) "
150
164
  end
151
165
 
@@ -169,12 +183,12 @@ module Deface
169
183
  end
170
184
 
171
185
  describe "#undo_erb_markup" do
172
- it "should revert <code erb-silent>" do
173
- Deface::Parser.undo_erb_markup!("<code erb-silent> method_name </code>").should == "<% method_name %>"
186
+ it "should revert <erb silent>" do
187
+ Deface::Parser.undo_erb_markup!("<erb silent> method_name </erb>").should == "<% method_name %>"
174
188
  end
175
189
 
176
- it "should revert <code erb-loud>" do
177
- Deface::Parser.undo_erb_markup!("<code erb-loud> method_name </code>").should == "<%= method_name %>"
190
+ it "should revert <erb loud>" do
191
+ Deface::Parser.undo_erb_markup!("<erb loud> method_name </erb>").should == "<%= method_name %>"
178
192
  end
179
193
 
180
194
  it "should revert data-erb-x attrs inside html tag" do
@@ -195,7 +209,7 @@ module Deface
195
209
  end
196
210
  end
197
211
 
198
- it "should unescape contents of code tags" do
212
+ it "should unescape contents of erb tags" do
199
213
  Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value' %>").should == "<% method(:key => 'value' %>"
200
214
  Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value'\n %>").should == "<% method(:key => 'value'\n %>"
201
215
  end
data/spec/spec_helper.rb CHANGED
@@ -44,13 +44,13 @@ shared_context "mock Rails" do
44
44
 
45
45
  # mock rails to keep specs FAST!
46
46
  unless defined? Rails
47
- Rails = mock 'Rails'
47
+ Rails = double 'Rails'
48
48
  end
49
49
 
50
50
  Rails.stub :version => rails_version
51
51
 
52
- Rails.stub :application => mock('application')
53
- Rails.application.stub :config => mock('config')
52
+ Rails.stub :application => double('application')
53
+ Rails.application.stub :config => double('config')
54
54
  Rails.application.config.stub :cache_classes => true
55
55
  Rails.application.config.stub :deface => ActiveSupport::OrderedOptions.new
56
56
  Rails.application.config.deface.enabled = true
@@ -61,13 +61,13 @@ shared_context "mock Rails" do
61
61
 
62
62
  Rails.stub :root => Pathname.new('spec/dummy')
63
63
 
64
- Rails.stub :logger => mock('logger')
64
+ Rails.stub :logger => double('logger')
65
65
  Rails.logger.stub(:error)
66
66
  Rails.logger.stub(:warning)
67
67
  Rails.logger.stub(:info)
68
68
  Rails.logger.stub(:debug)
69
69
 
70
- Time.stub :zone => mock('zone')
70
+ Time.stub :zone => double('zone')
71
71
  Time.zone.stub(:now).and_return Time.parse('1979-05-25')
72
72
 
73
73
  require "haml/template/plugin"
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deface
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
5
- prerelease: 6
4
+ version: 1.0.0.rc4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian D Quinn
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,103 +27,90 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rails
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '3.1'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '3.1'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: colorize
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.5.8
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.5.8
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: 2.11.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: 2.11.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: haml
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: 3.1.4
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: 3.1.4
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: slim
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: 2.0.0
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: 2.0.0
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: simplecov
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: 0.6.4
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: 0.6.4
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: generator_spec
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -146,10 +129,12 @@ executables: []
146
129
  extensions: []
147
130
  extra_rdoc_files:
148
131
  - README.markdown
132
+ - CHANGELOG.markdown
149
133
  files:
150
134
  - .gitignore
151
135
  - .rspec
152
136
  - .travis.yml
137
+ - CHANGELOG.markdown
153
138
  - Gemfile
154
139
  - MIT-LICENSE
155
140
  - README.markdown
@@ -249,28 +234,27 @@ files:
249
234
  - tasks/utils.rake
250
235
  homepage: https://github.com/spree/deface
251
236
  licenses: []
237
+ metadata: {}
252
238
  post_install_message:
253
239
  rdoc_options:
254
240
  - --charset=UTF-8
255
241
  require_paths:
256
242
  - lib
257
243
  required_ruby_version: !ruby/object:Gem::Requirement
258
- none: false
259
244
  requirements:
260
- - - ! '>='
245
+ - - '>='
261
246
  - !ruby/object:Gem::Version
262
247
  version: '0'
263
248
  required_rubygems_version: !ruby/object:Gem::Requirement
264
- none: false
265
249
  requirements:
266
- - - ! '>'
250
+ - - '>'
267
251
  - !ruby/object:Gem::Version
268
252
  version: 1.3.1
269
253
  requirements: []
270
254
  rubyforge_project:
271
- rubygems_version: 1.8.25
255
+ rubygems_version: 2.0.3
272
256
  signing_key:
273
- specification_version: 3
257
+ specification_version: 4
274
258
  summary: Deface is a library that allows you to customize ERB, Haml and Slim views
275
259
  in Rails
276
260
  test_files:
@@ -311,4 +295,3 @@ test_files:
311
295
  - spec/deface/utils/failure_finder_spec.rb
312
296
  - spec/generators/deface/override_generator_spec.rb
313
297
  - spec/spec_helper.rb
314
- has_rdoc: