deface 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/README.markdown +6 -2
- data/deface.gemspec +6 -5
- data/lib/deface.rb +3 -1
- data/lib/deface/action_view_extensions.rb +35 -3
- data/lib/deface/applicator.rb +192 -0
- data/lib/deface/environment.rb +8 -7
- data/lib/deface/haml_converter.rb +65 -0
- data/lib/deface/original_validator.rb +34 -0
- data/lib/deface/override.rb +56 -183
- data/lib/deface/railtie.rb +18 -8
- data/lib/deface/search.rb +22 -0
- data/lib/deface/template_helper.rb +10 -1
- data/spec/assets/shared/_hello.html.haml +1 -0
- data/spec/assets/shared/pirate.html.haml +5 -0
- data/spec/deface/action_view_template_spec.rb +52 -0
- data/spec/deface/applicator_spec.rb +367 -0
- data/spec/deface/environment_spec.rb +8 -3
- data/spec/deface/haml_converter_spec.rb +62 -0
- data/spec/deface/override_spec.rb +126 -5
- data/spec/deface/template_helper_spec.rb +21 -3
- data/spec/spec_helper.rb +17 -0
- metadata +42 -14
- data/spec/deface/template_spec.rb +0 -286
@@ -37,8 +37,9 @@ module Deface
|
|
37
37
|
@original = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
38
38
|
end
|
39
39
|
|
40
|
-
it "should not validate" do
|
41
|
-
|
40
|
+
it "should warn but not validate" do
|
41
|
+
Rails.logger.should_receive(:info).once
|
42
|
+
@override.validate_original("<p>this gets ignored</p>").should be_nil
|
42
43
|
end
|
43
44
|
|
44
45
|
end
|
@@ -61,6 +62,9 @@ module Deface
|
|
61
62
|
describe "#find" do
|
62
63
|
it "should find by virtual_path" do
|
63
64
|
Deface::Override.find({:virtual_path => "posts/index"}).size.should == 1
|
65
|
+
Deface::Override.find({:virtual_path => "/posts/index"}).size.should == 1
|
66
|
+
Deface::Override.find({:virtual_path => "/posts/index.html"}).size.should == 1
|
67
|
+
Deface::Override.find({:virtual_path => "posts/index.html"}).size.should == 1
|
64
68
|
end
|
65
69
|
|
66
70
|
it "should return empty array when no details hash passed" do
|
@@ -88,7 +92,31 @@ module Deface
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
|
-
describe "with :
|
95
|
+
describe "with :erb" do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return un-convert text as source" do
|
102
|
+
@override.source.should == "<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "with :haml" do
|
107
|
+
|
108
|
+
before(:each) do
|
109
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1",
|
110
|
+
:haml => %q{%strong{:class => "code", :id => "message"}= 'Hello, World!'})
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return erb converted from haml as source" do
|
114
|
+
@override.source.should == "<strong class='code' id='message'><%= 'Hello, World!' %>\n</strong>\n"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
describe "with :partial containing erb" do
|
92
120
|
|
93
121
|
before(:each) do
|
94
122
|
#stub view paths to be local spec/assets directory
|
@@ -139,7 +167,7 @@ module Deface
|
|
139
167
|
end
|
140
168
|
|
141
169
|
it "should return escaped source" do
|
142
|
-
@override.source_element.should be_an_instance_of Nokogiri::HTML::DocumentFragment
|
170
|
+
@override.source_element.should be_an_instance_of Nokogiri::HTML::DocumentFragment
|
143
171
|
@override.source_element.to_s.should == "<code erb-loud> method :opt => 'x' & 'y' </code>"
|
144
172
|
#do it twice to ensure it doesn't change as it's destructive
|
145
173
|
@override.source_element.to_s.should == "<code erb-loud> method :opt => 'x' & 'y' </code>"
|
@@ -229,7 +257,6 @@ module Deface
|
|
229
257
|
|
230
258
|
end
|
231
259
|
|
232
|
-
|
233
260
|
describe "#end_selector" do
|
234
261
|
it "should return nil when closing_selector is not defined" do
|
235
262
|
@override.end_selector.should be_nil
|
@@ -251,6 +278,100 @@ module Deface
|
|
251
278
|
end
|
252
279
|
end
|
253
280
|
|
281
|
+
describe "#digest" do
|
282
|
+
before { @digest = @override.digest }
|
283
|
+
|
284
|
+
it "should return hex digest based on override's args" do
|
285
|
+
@override.digest.should =~ /[a-f0-9]{32}/
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should change the digest when any args change" do
|
289
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>Argh!</h1>")
|
290
|
+
@override.digest.should_not == @digest
|
291
|
+
|
292
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
293
|
+
@override.digest.should == @digest
|
294
|
+
|
295
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>I'm a pirate!</h1>")
|
296
|
+
@override.digest.should_not == @digest
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "self#digest" do
|
301
|
+
before do
|
302
|
+
@second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "p", :text => "<pre>this is code?</pre>")
|
303
|
+
|
304
|
+
@digest = Deface::Override.digest(:virtual_path => "posts/index")
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should return hex digest based on all applicable overrides" do
|
308
|
+
Deface::Override.digest(:virtual_path => "posts/index").should =~ /[a-f0-9]{32}/
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should change the digest when any args change for any override" do
|
312
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>Argh!</h1>")
|
313
|
+
Deface::Override.digest(:virtual_path => "posts/index").should_not == @digest
|
314
|
+
|
315
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
316
|
+
Deface::Override.digest(:virtual_path => "posts/index").should == @digest
|
317
|
+
|
318
|
+
@second = Deface::Override.new(:virtual_path => "posts/index", :name => "2nd", :insert_after => "p", :text => "<pre>this is code?</pre>")
|
319
|
+
Deface::Override.digest(:virtual_path => "posts/index").should_not == @digest
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should change the digest when overrides are removed / added" do
|
323
|
+
Deface::Override.all.clear
|
324
|
+
|
325
|
+
@new_digest = Deface::Override.digest(:virtual_path => "posts/index")
|
326
|
+
@new_digest.should_not == @digest
|
327
|
+
|
328
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
329
|
+
Deface::Override.digest(:virtual_path => "posts/index").should_not == @new_digest
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
describe "#expire_compiled_template" do
|
334
|
+
before do
|
335
|
+
@compiled_templates = ActionView::CompiledTemplates
|
336
|
+
|
337
|
+
ActionView::CompiledTemplates.instance_methods.each do |method_name|
|
338
|
+
ActionView::CompiledTemplates.send :remove_method, method_name
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should remove compiled method when method name matches virtual path but not digest" do
|
343
|
+
module ActionView::CompiledTemplates
|
344
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
345
|
+
true #not a real method
|
346
|
+
end
|
347
|
+
|
348
|
+
def _f34556de606cec51d4f6791163fab456_posts_edit_123123123
|
349
|
+
true #not a real method
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
ActionView::CompiledTemplates.instance_methods.size.should == 2
|
355
|
+
@override.send(:expire_compiled_template)
|
356
|
+
ActionView::CompiledTemplates.instance_methods.size.should == 1
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should not remove compiled method when virtual path and digest matach" do
|
360
|
+
|
361
|
+
module ActionView::CompiledTemplates
|
362
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
363
|
+
true #not a real method
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
Deface::Override.should_receive(:digest).and_return('e235fa404c3c2281d4f6791162b1c638')
|
368
|
+
|
369
|
+
ActionView::CompiledTemplates.instance_methods.size.should == 1
|
370
|
+
@override.send(:expire_compiled_template)
|
371
|
+
ActionView::CompiledTemplates.instance_methods.size.should == 1
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
254
375
|
end
|
255
376
|
|
256
377
|
end
|
@@ -16,10 +16,18 @@ module Deface
|
|
16
16
|
load_template_source("shared/post", true).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
17
17
|
end
|
18
18
|
|
19
|
+
it "should return converted source for partial containing haml" do
|
20
|
+
load_template_source("shared/hello", true).should =="<div class='<%= @some %>' id='message'><%= 'Hello, World!' %>\n</div>\n"
|
21
|
+
end
|
22
|
+
|
19
23
|
it "should return source for template" do
|
20
24
|
load_template_source("shared/person", false).should == "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
|
21
25
|
end
|
22
26
|
|
27
|
+
it "should return converted source for template containing haml" do
|
28
|
+
load_template_source("shared/pirate", false).gsub(/\s/, '').should == "<divid='content'><divclass='left'><p><%=print_information%></p></div><divclass='right'id='<%=@right%>'><%=render:partial=>\"sidebar\"%></div></div>"
|
29
|
+
end
|
30
|
+
|
23
31
|
it "should return source for namespaced template" do
|
24
32
|
load_template_source("admin/posts/index", false).should == "<h1>Manage Posts</h1>\n"
|
25
33
|
end
|
@@ -36,21 +44,31 @@ module Deface
|
|
36
44
|
before(:each) do
|
37
45
|
Deface::Override.new(:virtual_path => "shared/_post", :name => "shared#post", :remove => "p")
|
38
46
|
Deface::Override.new(:virtual_path => "shared/person", :name => "shared#person", :replace => "p", :text => "<h1>Argh!</h1>")
|
47
|
+
Deface::Override.new(:virtual_path => "shared/_hello", :name => "shared#hello", :replace_contents => "div#message", :text => "<%= 'Goodbye World!' %>")
|
48
|
+
Deface::Override.new(:virtual_path => "shared/pirate", :name => "shared#pirate", :replace => "p", :text => "<h1>Argh!</h1>")
|
39
49
|
Deface::Override.new(:virtual_path => "admin/posts/index", :name => "admin#posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
40
50
|
end
|
41
51
|
|
42
|
-
it "should return source for partial including overrides" do
|
52
|
+
it "should return overridden source for partial including overrides" do
|
43
53
|
load_template_source("shared/post", true).should == "\n<%= \"And I've got ERB\" %>"
|
44
54
|
end
|
45
55
|
|
46
|
-
it "should return source for partial
|
56
|
+
it "should return converted and overridden source for partial containing haml" do
|
57
|
+
load_template_source("shared/hello", true).should =="<div class=\"<%= @some %>\" id=\"message\"><%= 'Goodbye World!' %></div>"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return overridden source for partial excluding overrides" do
|
47
61
|
load_template_source("shared/post", true, false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
48
62
|
end
|
49
63
|
|
50
|
-
it "should return source for template including overrides" do
|
64
|
+
it "should return overridden source for template including overrides" do
|
51
65
|
load_template_source("shared/person", false).should == "<h1>Argh!</h1>\n<%= \"I've got ERB too\" %>"
|
52
66
|
end
|
53
67
|
|
68
|
+
it "should return converted and overridden source for template containing haml" do
|
69
|
+
load_template_source("shared/pirate", false).gsub(/\s/, '').should == "<divid=\"content\"><divclass=\"left\"><h1>Argh!</h1></div><divclass=\"right\"id=\"<%=@right%>\"><%=render:partial=>\"sidebar\"%></div></div>"
|
70
|
+
end
|
71
|
+
|
54
72
|
it "should return source for namespaced template including overrides" do
|
55
73
|
load_template_source("admin/posts/index", false).should == "<h1>Argh!</h1>"
|
56
74
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,21 +3,37 @@ require 'rspec'
|
|
3
3
|
require 'action_view'
|
4
4
|
require 'action_controller'
|
5
5
|
require 'deface'
|
6
|
+
#have to manually require following three for testing purposes
|
7
|
+
require 'deface/action_view_extensions'
|
8
|
+
require 'haml'
|
9
|
+
require 'deface/haml_converter'
|
10
|
+
|
11
|
+
Haml.init_rails(nil)
|
6
12
|
|
7
13
|
RSpec.configure do |config|
|
8
14
|
config.mock_framework = :rspec
|
9
15
|
end
|
10
16
|
|
17
|
+
module ActionView::CompiledTemplates
|
18
|
+
#empty module for testing purposes
|
19
|
+
end
|
20
|
+
|
11
21
|
shared_context "mock Rails" do
|
12
22
|
before(:each) do
|
13
23
|
unless defined? Rails
|
14
24
|
Rails = mock 'Rails'
|
15
25
|
end
|
26
|
+
|
16
27
|
Rails.stub :application => mock('application')
|
17
28
|
Rails.application.stub :config => mock('config')
|
18
29
|
Rails.application.config.stub :cache_classes => true
|
19
30
|
Rails.application.config.stub :deface => ActiveSupport::OrderedOptions.new
|
20
31
|
Rails.application.config.deface.enabled = true
|
32
|
+
|
33
|
+
Rails.stub :logger => mock('logger')
|
34
|
+
Rails.logger.stub(:error)
|
35
|
+
Rails.logger.stub(:warning)
|
36
|
+
Rails.logger.stub(:info)
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
@@ -26,5 +42,6 @@ shared_context "mock Rails.application" do
|
|
26
42
|
|
27
43
|
before(:each) do
|
28
44
|
Rails.application.config.stub :deface => Deface::Environment.new
|
45
|
+
Rails.application.config.deface.haml_support = true
|
29
46
|
end
|
30
47
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian D Quinn
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-03-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -57,16 +57,32 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 47
|
61
61
|
segments:
|
62
62
|
- 2
|
63
|
-
-
|
63
|
+
- 8
|
64
64
|
- 0
|
65
|
-
version: 2.
|
65
|
+
version: 2.8.0
|
66
66
|
type: :development
|
67
67
|
version_requirements: *id003
|
68
|
-
|
69
|
-
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: haml
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 11
|
77
|
+
segments:
|
78
|
+
- 3
|
79
|
+
- 1
|
80
|
+
- 4
|
81
|
+
version: 3.1.4
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
description: Deface is a library that allows you to customize ERB & HAML views in a Rails application without editing the underlying view.
|
85
|
+
email: brian@spreecommerce.com
|
70
86
|
executables: []
|
71
87
|
|
72
88
|
extensions: []
|
@@ -84,19 +100,27 @@ files:
|
|
84
100
|
- init.rb
|
85
101
|
- lib/deface.rb
|
86
102
|
- lib/deface/action_view_extensions.rb
|
103
|
+
- lib/deface/applicator.rb
|
87
104
|
- lib/deface/environment.rb
|
105
|
+
- lib/deface/haml_converter.rb
|
106
|
+
- lib/deface/original_validator.rb
|
88
107
|
- lib/deface/override.rb
|
89
108
|
- lib/deface/parser.rb
|
90
109
|
- lib/deface/railtie.rb
|
110
|
+
- lib/deface/search.rb
|
91
111
|
- lib/deface/template_helper.rb
|
92
112
|
- spec/assets/admin/posts/index.html.erb
|
113
|
+
- spec/assets/shared/_hello.html.haml
|
93
114
|
- spec/assets/shared/_post.html.erb
|
94
115
|
- spec/assets/shared/person.html.erb
|
116
|
+
- spec/assets/shared/pirate.html.haml
|
117
|
+
- spec/deface/action_view_template_spec.rb
|
118
|
+
- spec/deface/applicator_spec.rb
|
95
119
|
- spec/deface/environment_spec.rb
|
120
|
+
- spec/deface/haml_converter_spec.rb
|
96
121
|
- spec/deface/override_spec.rb
|
97
122
|
- spec/deface/parser_spec.rb
|
98
123
|
- spec/deface/template_helper_spec.rb
|
99
|
-
- spec/deface/template_spec.rb
|
100
124
|
- spec/spec_helper.rb
|
101
125
|
- tasks/precompile.rake
|
102
126
|
- tasks/utils.rake
|
@@ -129,17 +153,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
153
|
requirements: []
|
130
154
|
|
131
155
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.8.
|
156
|
+
rubygems_version: 1.8.15
|
133
157
|
signing_key:
|
134
158
|
specification_version: 3
|
135
|
-
summary: Deface is a library that allows you to customize ERB views in Rails
|
159
|
+
summary: Deface is a library that allows you to customize ERB & HAML views in Rails
|
136
160
|
test_files:
|
137
161
|
- spec/assets/admin/posts/index.html.erb
|
162
|
+
- spec/assets/shared/_hello.html.haml
|
138
163
|
- spec/assets/shared/_post.html.erb
|
139
164
|
- spec/assets/shared/person.html.erb
|
165
|
+
- spec/assets/shared/pirate.html.haml
|
166
|
+
- spec/deface/action_view_template_spec.rb
|
167
|
+
- spec/deface/applicator_spec.rb
|
140
168
|
- spec/deface/environment_spec.rb
|
169
|
+
- spec/deface/haml_converter_spec.rb
|
141
170
|
- spec/deface/override_spec.rb
|
142
171
|
- spec/deface/parser_spec.rb
|
143
172
|
- spec/deface/template_helper_spec.rb
|
144
|
-
- spec/deface/template_spec.rb
|
145
173
|
- spec/spec_helper.rb
|
@@ -1,286 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
describe Template do
|
5
|
-
include_context "mock Rails.application"
|
6
|
-
|
7
|
-
describe "with no overrides defined" do
|
8
|
-
before(:each) do
|
9
|
-
@updated_at = Time.now - 600
|
10
|
-
@template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html, :updated_at => @updated_at})
|
11
|
-
#stub for Rails < 3.1
|
12
|
-
unless defined?(@template.updated_at)
|
13
|
-
@template.stub(:updated_at).and_return(@updated_at)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should initialize new template object" do
|
18
|
-
@template.is_a?(ActionView::Template).should == true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return unmodified source" do
|
22
|
-
@template.source.should == "<p>test</p>"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should not change updated_at" do
|
26
|
-
@template.updated_at.should == @updated_at
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "with a single remove override defined" do
|
32
|
-
before(:each) do
|
33
|
-
@updated_at = Time.now - 300
|
34
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>")
|
35
|
-
@template = ActionView::Template.new("<p>test</p><%= raw(text) %>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html, :updated_at => @updated_at})
|
36
|
-
#stub for Rails < 3.1
|
37
|
-
unless defined?(@template.updated_at)
|
38
|
-
@template.stub(:updated_at).and_return(@updated_at + 500)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return modified source" do
|
43
|
-
@template.source.should == "<%= raw(text) %>"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should change updated_at" do
|
47
|
-
@template.updated_at.should > @updated_at
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "with a single remove override with closing_selector defined" do
|
52
|
-
before(:each) do
|
53
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "h1", :closing_selector => "h2")
|
54
|
-
@template = ActionView::Template.new("<h2>I should be safe</h2><span>Before!</span><h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2><span>After!</span>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should return modified source" do
|
58
|
-
@template.source.should == "<h2>I should be safe</h2><span>Before!</span><span>After!</span>"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "with a single replace override defined" do
|
63
|
-
before(:each) do
|
64
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "p", :text => "<h1>Argh!</h1>")
|
65
|
-
@template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return modified source" do
|
69
|
-
@template.source.should == "<h1>Argh!</h1>"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "with a single replace override with closing_selector defined" do
|
74
|
-
before(:each) do
|
75
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>")
|
76
|
-
@template = ActionView::Template.new("<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should return modified source" do
|
80
|
-
@template.source.should == "<span>Argh!</span>"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "with a single replace_contents override defined" do
|
85
|
-
before(:each) do
|
86
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "p", :text => "<h1>Argh!</h1>")
|
87
|
-
@template = ActionView::Template.new("<p><span>Hello</span>I am not a <em>pirate</em></p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should return modified source" do
|
91
|
-
@template.source.should == "<p><h1>Argh!</h1></p>"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "with a single replace_contents override with closing_selector defined" do
|
96
|
-
before(:each) do
|
97
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace_contents => "h1", :closing_selector => "h2", :text => "<span>Argh!</span>")
|
98
|
-
@template = ActionView::Template.new("<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should return modified source" do
|
102
|
-
@template.source.should == "<h1>start</h1><span>Argh!</span><h2>end</h2>"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "with a single insert_after override defined" do
|
107
|
-
before(:each) do
|
108
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "img.button", :text => "<% help %>")
|
109
|
-
|
110
|
-
@template = ActionView::Template.new("<div><img class=\"button\" src=\"path/to/button.png\"></div>",
|
111
|
-
"/path/to/file.erb",
|
112
|
-
ActionView::Template::Handlers::ERB,
|
113
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should return modified source" do
|
117
|
-
@template.source.gsub("\n", "").should == "<div><img class=\"button\" src=\"path/to/button.png\"><% help %></div>"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "with a single insert_before override defined" do
|
122
|
-
before(:each) do
|
123
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "ul li:last", :text => "<%= help %>")
|
124
|
-
|
125
|
-
@template = ActionView::Template.new("<ul><li>first</li><li>second</li><li>third</li></ul>",
|
126
|
-
"/path/to/file.erb",
|
127
|
-
ActionView::Template::Handlers::ERB,
|
128
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should return modified source" do
|
132
|
-
@template.source.gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><%= help %></ul>"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe "with a single insert_top override defined" do
|
137
|
-
before(:each) do
|
138
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>me first</li>")
|
139
|
-
|
140
|
-
@template = ActionView::Template.new("<ul><li>first</li><li>second</li><li>third</li></ul>",
|
141
|
-
"/path/to/file.erb",
|
142
|
-
ActionView::Template::Handlers::ERB,
|
143
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should return modified source" do
|
147
|
-
@template.source.gsub("\n", "").should == "<ul><li>me first</li><li>first</li><li>second</li><li>third</li></ul>"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "with a single insert_top override defined when targetted elemenet has no children" do
|
152
|
-
before(:each) do
|
153
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>first</li><li>second</li><li>third</li>")
|
154
|
-
|
155
|
-
@template = ActionView::Template.new("<ul></ul>",
|
156
|
-
"/path/to/file.erb",
|
157
|
-
ActionView::Template::Handlers::ERB,
|
158
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should return modified source" do
|
162
|
-
@template.source.gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li></ul>"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe "with a single insert_bottom override defined" do
|
167
|
-
before(:each) do
|
168
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>")
|
169
|
-
|
170
|
-
@template = ActionView::Template.new("<ul><li>first</li><li>second</li><li>third</li></ul>",
|
171
|
-
"/path/to/file.erb",
|
172
|
-
ActionView::Template::Handlers::ERB,
|
173
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should return modified source" do
|
177
|
-
@template.source.gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><li>I'm always last</li></ul>"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "with a single insert_bottom override defined when targetted elemenet has no children" do
|
182
|
-
before(:each) do
|
183
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>")
|
184
|
-
|
185
|
-
@template = ActionView::Template.new("<ul></ul>",
|
186
|
-
"/path/to/file.erb",
|
187
|
-
ActionView::Template::Handlers::ERB,
|
188
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should return modified source" do
|
192
|
-
@template.source.gsub("\n", "").should == "<ul><li>I'm always last</li></ul>"
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe "with a single set_attributes override defined" do
|
197
|
-
before(:each) do
|
198
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
199
|
-
:attributes => {:class => 'pretty', :alt => 'something interesting'})
|
200
|
-
|
201
|
-
@template = ActionView::Template.new("<div><img class=\"button\" src=\"path/to/button.png\"></div>",
|
202
|
-
"/path/to/file.erb",
|
203
|
-
ActionView::Template::Handlers::ERB,
|
204
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should return modified source" do
|
208
|
-
@template.source.gsub("\n", "").should == "<div><img class=\"pretty\" src=\"path/to/button.png\" alt=\"something interesting\"></div>"
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
describe "with a single html surround override defined" do
|
214
|
-
before(:each) do
|
215
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<h1>It's behind you!</h1><div><%= render_original %></div>")
|
216
|
-
@template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should return modified source" do
|
220
|
-
@template.source.should == "<h1>It's behind you!</h1><div><p>test</p></div>"
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe "with a single erb surround override defined" do
|
225
|
-
before(:each) do
|
226
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>")
|
227
|
-
@template = ActionView::Template.new("<span><p>test</p></span>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should return modified source" do
|
231
|
-
@template.source.gsub("\n", '').should == "<span><% some_method('test') do %><p>test</p><% end %></span>"
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "with a single html surround_contents override defined" do
|
236
|
-
before(:each) do
|
237
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "div", :text => "<span><%= render_original %></span>")
|
238
|
-
@template = ActionView::Template.new("<h4>yay!</h4><div><p>test</p></div>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should return modified source" do
|
242
|
-
@template.source.should == "<h4>yay!</h4><div><span><p>test</p></span></div>"
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "with a single erb surround_contents override defined" do
|
247
|
-
before(:each) do
|
248
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "p", :text => "<% if 1==1 %><%= render_original %><% end %>")
|
249
|
-
@template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should return modified source" do
|
253
|
-
@template.source.should == "<p><% if 1==1 %>test<% end %></p>"
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
describe "with a single disabled override defined" do
|
258
|
-
before(:each) do
|
259
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>", :disabled => true)
|
260
|
-
@template = ActionView::Template.new("<p>test</p><%= raw(text) %>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should return unmodified source" do
|
264
|
-
@template.source.should == "<p>test</p><%= raw(text) %>"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
describe "with mulitple sequenced overrides defined" do
|
269
|
-
before(:each) do
|
270
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "third", :insert_after => "li:contains('second')", :text => "<li>third</li>", :sequence => {:after => "second"})
|
271
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "li", :text => "<li>second</li>", :sequence => {:after => "first"})
|
272
|
-
Deface::Override.new(:virtual_path => "posts/index", :name => "first", :replace => "li", :text => "<li>first</li>")
|
273
|
-
|
274
|
-
@template = ActionView::Template.new("<ul><li>replaced</li></ul>",
|
275
|
-
"/path/to/file.erb",
|
276
|
-
ActionView::Template::Handlers::ERB,
|
277
|
-
{:virtual_path=>"posts/index", :format=>:html})
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should return modified source" do
|
281
|
-
@template.source.gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li></ul>"
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
end
|
286
|
-
end
|