deface 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/deface.gemspec +3 -22
- data/lib/deface.rb +1 -0
- data/lib/deface/action_view_extensions.rb +1 -26
- data/lib/deface/override.rb +111 -12
- data/lib/deface/parser.rb +24 -8
- data/lib/deface/template_helper.rb +21 -0
- data/spec/assets/admin/posts/index.html.erb +1 -0
- data/spec/assets/shared/_post.html.erb +1 -0
- data/spec/assets/shared/person.html.erb +1 -0
- data/spec/deface/override_spec.rb +19 -2
- data/spec/deface/parser_spec.rb +47 -8
- data/spec/deface/template_helper_spec.rb +31 -0
- data/spec/deface/template_spec.rb +42 -0
- metadata +16 -6
data/.gitignore
ADDED
data/deface.gemspec
CHANGED
@@ -5,39 +5,20 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{deface}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
10
|
s.authors = ["Brian Quinn"]
|
12
|
-
s.date = %q{2010-08-31}
|
13
11
|
s.description = %q{Deface is a library that allows you to customize ERB views in a Rails application without editing the underlying view.}
|
14
12
|
s.email = %q{brian@railsdog.com}
|
15
13
|
s.extra_rdoc_files = [
|
16
14
|
"README.markdown"
|
17
15
|
]
|
18
|
-
s.files
|
19
|
-
|
20
|
-
"README.markdown",
|
21
|
-
"Rakefile",
|
22
|
-
"VERSION",
|
23
|
-
"deface.gemspec",
|
24
|
-
"init.rb",
|
25
|
-
"lib/deface.rb",
|
26
|
-
"lib/deface/action_view_extensions.rb",
|
27
|
-
"lib/deface/override.rb",
|
28
|
-
"lib/deface/parser.rb"
|
29
|
-
]
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
18
|
s.homepage = %q{http://github.com/BDQ/Deface}
|
31
19
|
s.rdoc_options = ["--charset=UTF-8"]
|
32
20
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.3.7}
|
34
21
|
s.summary = %q{Deface is a library that allows you to customize ERB views in Rails}
|
35
|
-
s.test_files = [
|
36
|
-
"spec/deface/override_spec.rb",
|
37
|
-
"spec/deface/parser_spec.rb",
|
38
|
-
"spec/deface/template_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
22
|
|
42
23
|
if s.respond_to? :specification_version then
|
43
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/deface.rb
CHANGED
@@ -2,32 +2,7 @@ ActionView::Template.class_eval do
|
|
2
2
|
alias_method :rails_initialize, :initialize
|
3
3
|
|
4
4
|
def initialize(source, identifier, handler, details)
|
5
|
-
|
6
|
-
|
7
|
-
unless overrides.empty?
|
8
|
-
doc = Deface::Parser.convert_fragment(source)
|
9
|
-
|
10
|
-
overrides.each do |override|
|
11
|
-
doc.css(override.selector).each do |match|
|
12
|
-
|
13
|
-
match.replace case override.action
|
14
|
-
when :remove
|
15
|
-
""
|
16
|
-
when :replace
|
17
|
-
Deface::Parser.convert_fragment(override.source.clone)
|
18
|
-
when :insert_before
|
19
|
-
Deface::Parser.convert_fragment(override.source.clone << match.to_s)
|
20
|
-
when :insert_after
|
21
|
-
Deface::Parser.convert_fragment(match.to_s << override.source.clone)
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
source = doc.to_s
|
28
|
-
|
29
|
-
Deface::Parser.undo_erb_markup!(source)
|
30
|
-
end
|
5
|
+
source = Deface::Override.apply(source, details)
|
31
6
|
|
32
7
|
rails_initialize(source, identifier, handler, details)
|
33
8
|
end
|
data/lib/deface/override.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Deface
|
2
2
|
class Override
|
3
|
+
include Deface::TemplateHelper
|
4
|
+
|
3
5
|
cattr_accessor :all, :actions
|
4
6
|
attr_accessor :args
|
5
7
|
|
6
8
|
@@all ||= {}
|
7
|
-
@@actions = [:remove, :replace, :insert_after, :insert_before]
|
9
|
+
@@actions = [:remove, :replace, :insert_after, :insert_before, :insert_top, :insert_bottom]
|
8
10
|
|
9
11
|
# Initializes new override, you must supply only one Target, Action & Source
|
10
12
|
# parameter for each override (and any number of Optional parameters).
|
@@ -21,6 +23,8 @@ module Deface
|
|
21
23
|
# * <tt>:replace</tt> - Replaces all elements that match the supplied selector
|
22
24
|
# * <tt>:insert_after</tt> - Inserts after all elements that match the supplied selector
|
23
25
|
# * <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
|
26
|
+
# * <tt>:insert_top</tt> - Inserts inside all elements that match the supplied selector, before all existing child
|
27
|
+
# * <tt>:insert_bottom</tt> - Inserts inside all elements that match the supplied selector, after all existing child
|
24
28
|
#
|
25
29
|
# ==== Source
|
26
30
|
#
|
@@ -32,10 +36,15 @@ module Deface
|
|
32
36
|
#
|
33
37
|
# * <tt>:name</tt> - Unique name for override so it can be identified and modified later.
|
34
38
|
# This needs to be unique within the same :virtual_path
|
39
|
+
# * <tt>:disabled</tt> - When set to true the override will not be applied.
|
40
|
+
|
35
41
|
|
36
42
|
def initialize(args)
|
37
43
|
@args = args
|
38
44
|
|
45
|
+
raise(ArgumentError, "Invalid action") if self.action.nil?
|
46
|
+
raise(ArgumentError, ":virtual_path must be defined") if args[:virtual_path].blank?
|
47
|
+
|
39
48
|
key = args[:virtual_path].to_sym
|
40
49
|
|
41
50
|
@@all[key] ||= {}
|
@@ -46,6 +55,10 @@ module Deface
|
|
46
55
|
@args[self.action]
|
47
56
|
end
|
48
57
|
|
58
|
+
def name
|
59
|
+
@args[:name]
|
60
|
+
end
|
61
|
+
|
49
62
|
def action
|
50
63
|
(@@actions & @args.keys).first
|
51
64
|
end
|
@@ -62,8 +75,100 @@ module Deface
|
|
62
75
|
Deface::Parser.erb_markup!(erb)
|
63
76
|
end
|
64
77
|
|
78
|
+
def source_element
|
79
|
+
@converted_source ||= Deface::Parser.convert(source.clone).to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
def disabled?
|
83
|
+
@args.key?(:disabled) ? @args[:disabled] : false
|
84
|
+
end
|
85
|
+
|
86
|
+
def end_selector
|
87
|
+
@args[:closing_selector]
|
88
|
+
end
|
89
|
+
|
90
|
+
# applies all applicable overrides to given source
|
91
|
+
#
|
92
|
+
def self.apply(source, details)
|
93
|
+
overrides = find(details)
|
94
|
+
@enable_logging ||= (defined?(Rails) == "constant" ? true : false)
|
95
|
+
|
96
|
+
if @enable_logging && overrides.size > 0
|
97
|
+
Rails.logger.info "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for #{details[:virtual_path]}"
|
98
|
+
end
|
99
|
+
|
100
|
+
unless overrides.empty?
|
101
|
+
doc = Deface::Parser.convert(source)
|
102
|
+
|
103
|
+
overrides.each do |override|
|
104
|
+
if override.disabled?
|
105
|
+
if @enable_logging
|
106
|
+
Rails.logger.info "\e[1;32mDeface:\e[0m #{override.name} is disabled"
|
107
|
+
end
|
108
|
+
next
|
109
|
+
end
|
110
|
+
|
111
|
+
if override.end_selector.blank?
|
112
|
+
# single css selector
|
113
|
+
|
114
|
+
matches = doc.css(override.selector)
|
115
|
+
|
116
|
+
if @enable_logging
|
117
|
+
Rails.logger.info "\e[1;32mDeface:\e[0m #{override.name} matched #{matches.size} times with #{override.selector}"
|
118
|
+
end
|
119
|
+
|
120
|
+
matches.each do |match|
|
121
|
+
case override.action
|
122
|
+
when :remove
|
123
|
+
match.replace ""
|
124
|
+
when :replace
|
125
|
+
match.replace override.source_element
|
126
|
+
when :insert_before
|
127
|
+
match.before override.source_element
|
128
|
+
when :insert_after
|
129
|
+
match.after override.source_element
|
130
|
+
when :insert_top
|
131
|
+
match.children.before(override.source_element)
|
132
|
+
when :insert_bottom
|
133
|
+
match.children.after(override.source_element)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
else
|
138
|
+
# targeting range of elements as end_selector is present
|
139
|
+
starting = doc.css(override.selector).first
|
140
|
+
if starting && starting.parent
|
141
|
+
ending = starting.parent.css(override.end_selector).first
|
142
|
+
else
|
143
|
+
ending = doc.css(override.end_selector).first
|
144
|
+
end
|
145
|
+
|
146
|
+
if starting && ending
|
147
|
+
elements = select_range(starting, ending)
|
148
|
+
|
149
|
+
if override.action == :replace
|
150
|
+
starting.before(override.source_element)
|
151
|
+
end
|
152
|
+
|
153
|
+
#now remove all matched elements
|
154
|
+
elements.map &:remove
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
source = doc.to_s
|
161
|
+
|
162
|
+
Deface::Parser.undo_erb_markup!(source)
|
163
|
+
end
|
164
|
+
|
165
|
+
source
|
166
|
+
end
|
167
|
+
|
168
|
+
# finds all applicable overrides for supplied template
|
169
|
+
#
|
65
170
|
def self.find(details)
|
66
|
-
return []
|
171
|
+
return [] if @@all.empty? || details.empty?
|
67
172
|
|
68
173
|
result = []
|
69
174
|
|
@@ -74,16 +179,10 @@ module Deface
|
|
74
179
|
end
|
75
180
|
|
76
181
|
private
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
if parts.size == 2
|
83
|
-
return @lookup_context.find(parts[1], parts[0], partial).source
|
84
|
-
else
|
85
|
-
return ""
|
86
|
-
end
|
182
|
+
# finds all elements upto closing sibling in nokgiri document
|
183
|
+
#
|
184
|
+
def self.select_range(first, last)
|
185
|
+
first == last ? [first] : [first, *select_range(first.next, last)]
|
87
186
|
end
|
88
187
|
|
89
188
|
end
|
data/lib/deface/parser.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'erubis'
|
3
|
+
require 'cgi'
|
3
4
|
|
4
5
|
module Deface
|
5
6
|
class Parser
|
@@ -11,6 +12,11 @@ module Deface
|
|
11
12
|
{"%>" => "</code>"} ]
|
12
13
|
|
13
14
|
replacements.each{ |h| h.each { |replace, with| source.gsub! replace, with } }
|
15
|
+
|
16
|
+
source.scan(/(<code.*?>)((?:(?!<\/code>)[\s\S])*)(<\/code>)/).each do |match|
|
17
|
+
source.gsub!("#{match[0]}#{match[1]}#{match[2]}", "#{match[0]}#{CGI.escapeHTML(match[1])}#{match[2]}")
|
18
|
+
end
|
19
|
+
|
14
20
|
source
|
15
21
|
end
|
16
22
|
|
@@ -20,20 +26,30 @@ module Deface
|
|
20
26
|
replacements = [ {"<code erb-silent>" => '<%'},
|
21
27
|
{"<code erb-loud>" => '<%='},
|
22
28
|
{"</code>" => '%>'},
|
23
|
-
{/(<|<)code
|
24
|
-
{/(<|<)code
|
25
|
-
{/(<|<)\/code(>|>)/
|
26
|
-
{/(?!=<%=?)>(?=.*%>)/ => '>'},
|
27
|
-
{/(?!=<%=?)<(?=.*%>)/ => '<'}]
|
29
|
+
{/(<|<)code(\s|%20)erb-silent(>|>)/ => '<%'},
|
30
|
+
{/(<|<)code(\s|%20)erb-loud(>|>)/ => '<%='},
|
31
|
+
{/(<|<)\/code(>|>)/ => '%>'} ]
|
28
32
|
|
29
33
|
replacements.each{ |h| h.each { |replace, with| source.gsub! replace, with } }
|
34
|
+
|
35
|
+
#un-escape changes from Nokogiri and erb-markup!
|
36
|
+
source.scan(/(<%.*?)((?:(?!%>)[\s\S])*)(%>)/).each do |match|
|
37
|
+
escaped = URI.unescape match[1]
|
38
|
+
escaped = CGI.unescapeHTML CGI.unescapeHTML(escaped)
|
39
|
+
source.gsub!("#{match[0]}#{match[1]}#{match[2]}", "#{match[0]}#{escaped}#{match[2]}")
|
40
|
+
end
|
41
|
+
|
30
42
|
source
|
31
43
|
end
|
32
44
|
|
33
|
-
|
34
|
-
def self.convert_fragment(source)
|
45
|
+
def self.convert(source)
|
35
46
|
erb_markup!(source)
|
36
|
-
|
47
|
+
|
48
|
+
if source =~ /(<html.*?)((?:(?!>)[\s\S])*)(>)/
|
49
|
+
Nokogiri::HTML::Document.parse(source)
|
50
|
+
else
|
51
|
+
Nokogiri::HTML::DocumentFragment.parse(source)
|
52
|
+
end
|
37
53
|
end
|
38
54
|
|
39
55
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Deface
|
2
|
+
module TemplateHelper
|
3
|
+
|
4
|
+
# used to find source for a partial or template using virutal_path
|
5
|
+
def load_template_source(virtual_path, partial)
|
6
|
+
parts = virtual_path.split("/")
|
7
|
+
|
8
|
+
if parts.size == 2
|
9
|
+
prefix = ""
|
10
|
+
name = virtual_path
|
11
|
+
else
|
12
|
+
prefix = parts.shift
|
13
|
+
name = parts.join("/")
|
14
|
+
end
|
15
|
+
|
16
|
+
@lookup_context ||= ActionView::LookupContext.new(ActionController::Base.view_paths, {:formats => [:html]})
|
17
|
+
|
18
|
+
@lookup_context.find(name, prefix, partial).source
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Manage Posts</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>I'm from shared/post partial</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>I'm from shared/person template</p>
|
@@ -17,8 +17,14 @@ module Deface
|
|
17
17
|
@override.selector.should == "h1"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
describe "#find" do
|
21
|
+
it "should find by virtual_path" do
|
22
|
+
Deface::Override.find({:virtual_path => "posts/index"}).size.should == 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return empty array when no details hash passed" do
|
26
|
+
Deface::Override.find({}).should == []
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
describe "#new" do
|
@@ -71,6 +77,17 @@ module Deface
|
|
71
77
|
|
72
78
|
end
|
73
79
|
|
80
|
+
describe "#source_element" do
|
81
|
+
before(:each) do
|
82
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<%= method 'x' & 'y' %>")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return memoized escaped source" do
|
86
|
+
@override.source_element
|
87
|
+
@override.source_element.should == "<code erb-loud> method 'x' &amp; 'y' </code>"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
74
91
|
describe "when redefining an existing virutal_path and name" do
|
75
92
|
before(:each) do
|
76
93
|
@replacement = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Arrrr!</h1>")
|
data/spec/deface/parser_spec.rb
CHANGED
@@ -3,25 +3,50 @@ require 'spec_helper'
|
|
3
3
|
module Deface
|
4
4
|
describe Parser do
|
5
5
|
|
6
|
-
describe "#
|
7
|
-
it "should parse html" do
|
8
|
-
Deface::Parser.
|
6
|
+
describe "#convert" do
|
7
|
+
it "should parse html fragment" do
|
8
|
+
Deface::Parser.convert("<h1>Hello</h1>").should be_an_instance_of(Nokogiri::HTML::DocumentFragment)
|
9
|
+
Deface::Parser.convert("<h1>Hello</h1>").to_s.should == "<h1>Hello</h1>"
|
10
|
+
Deface::Parser.convert("<title>Hello</title>").should be_an_instance_of(Nokogiri::HTML::DocumentFragment)
|
11
|
+
Deface::Parser.convert("<title>Hello</title>").to_s.should == "<title>Hello</title>"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse html document" do
|
15
|
+
parsed = Deface::Parser.convert("<html><head><title>Hello</title></head><body>test</body>")
|
16
|
+
parsed.should be_an_instance_of(Nokogiri::HTML::Document)
|
17
|
+
parsed = parsed.to_s.split("\n")[1..-1]
|
18
|
+
parsed.should == "<html>\n<head><title>Hello</title></head>\n<body>test</body>\n</html>".split("\n") #ignore doctype added by noko
|
19
|
+
|
20
|
+
parsed = Deface::Parser.convert("<html><title>test</title></html>")
|
21
|
+
parsed.should be_an_instance_of(Nokogiri::HTML::Document)
|
22
|
+
parsed = parsed.to_s.split("\n")[1..-1]
|
23
|
+
parsed.should == "<html><head><title>test</title></head></html>".split("\n") #ignore doctype added by noko
|
24
|
+
|
25
|
+
|
26
|
+
parsed = Deface::Parser.convert("<html><p>test</p></html>")
|
27
|
+
parsed.should be_an_instance_of(Nokogiri::HTML::Document)
|
28
|
+
parsed = parsed.to_s.split("\n")[1..-1]
|
29
|
+
parsed.should == "<html><body><p>test</p></body></html>".split("\n") #ignore doctype added by noko
|
9
30
|
end
|
10
31
|
|
11
32
|
it "should convert <% ... %>" do
|
12
|
-
Deface::Parser.
|
33
|
+
Deface::Parser.convert("<% method_name %>").to_s.should == "<code erb-silent> method_name </code>"
|
13
34
|
end
|
14
35
|
|
15
36
|
it "should convert <%= ... %>" do
|
16
|
-
Deface::Parser.
|
37
|
+
Deface::Parser.convert("<%= method_name %>").to_s.should == "<code erb-loud> method_name </code>"
|
17
38
|
end
|
18
39
|
|
19
40
|
it "should convert nested <% ... %>" do
|
20
|
-
Deface::Parser.
|
41
|
+
Deface::Parser.convert("<p id=\"<% method_name %>\"></p>").to_s.should == "<p id=\"<code erb-silent> method_name </code>\"></p>"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should convert nested <%= ... %> including href attribute" do
|
45
|
+
Deface::Parser.convert(%(<a href="<%= x 'y' + "z" %>">A Link</a>)).to_s.should == "<a href=\"<code%20erb-loud>%20x%20'y'%20+%20%22z%22%20</code>\">A Link</a>"
|
21
46
|
end
|
22
47
|
|
23
|
-
it "should
|
24
|
-
Deface::Parser.
|
48
|
+
it "should escape contents code tags" do
|
49
|
+
Deface::Parser.convert("<% method_name(:key => 'value') %>").to_s.should == "<code erb-silent> method_name(:key => 'value') </code>"
|
25
50
|
end
|
26
51
|
end
|
27
52
|
|
@@ -38,10 +63,24 @@ module Deface
|
|
38
63
|
Deface::Parser.undo_erb_markup!("<p id=\"<code erb-silent> method_name > 1 </code>\"></p>").should == "<p id=\"<% method_name > 1 %>\"></p>"
|
39
64
|
end
|
40
65
|
|
66
|
+
it "should revert nested <code erb-silent> including href attribute" do
|
67
|
+
Deface::Parser.undo_erb_markup!("<a href=\"<code%20erb-silent>%20method_name%20</code>\">A Link</a>").should == "<a href=\"<% method_name %>\">A Link</a>"
|
68
|
+
end
|
69
|
+
|
41
70
|
it "should revert nested <code erb-loud>" do
|
42
71
|
Deface::Parser.undo_erb_markup!("<p id=\"<code erb-loud> method_name < 2 </code>\"></p>").should == "<p id=\"<%= method_name < 2 %>\"></p>"
|
43
72
|
end
|
44
73
|
|
74
|
+
it "should revert nested <code erb-loud> including href attribute" do
|
75
|
+
Deface::Parser.undo_erb_markup!("<a href=\"<code%20erb-loud>%20x%20'y'%20+%20'z'%20</code>\">A Link</a>").should == %(<a href="<%= x 'y' + 'z' %>">A Link</a>)
|
76
|
+
Deface::Parser.undo_erb_markup!("<a href=\"<code%20erb-loud>%20x%20'y'%20+%20%22z%22%20</code>\">A Link</a>").should == %(<a href="<%= x 'y' + "z" %>">A Link</a>)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should unescape contents of code tags" do
|
80
|
+
Deface::Parser.undo_erb_markup!("<% method(:key => 'value' %>").should == "<% method(:key => 'value' %>"
|
81
|
+
Deface::Parser.undo_erb_markup!("<% method(:key => 'value'\n %>").should == "<% method(:key => 'value'\n %>"
|
82
|
+
end
|
83
|
+
|
45
84
|
end
|
46
85
|
|
47
86
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Deface
|
4
|
+
describe TemplateHelper do
|
5
|
+
include Deface::TemplateHelper
|
6
|
+
|
7
|
+
describe "load_template_source" do
|
8
|
+
before do
|
9
|
+
#stub view paths to be local spec/assets directory
|
10
|
+
ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return source for partial" do
|
14
|
+
load_template_source("shared/_post", false).should == "<p>I'm from shared/post partial</p>\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return source for template" do
|
18
|
+
load_template_source("shared/person", false).should == "<p>I'm from shared/person template</p>\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return source for namespaced template" do
|
22
|
+
load_template_source("admin/posts/index", false).should == "<h1>Manage Posts</h1>\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise exception for non-existing file" do
|
26
|
+
lambda { load_template_source("tester/_post", false) }.should raise_error(ActionView::MissingTemplate)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -70,6 +70,48 @@ module ActionView
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
describe "with a single insert_top override defined" do
|
74
|
+
before(:all) do
|
75
|
+
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_top => "ul", :text => "<li>me first</li>")
|
76
|
+
|
77
|
+
@template = ActionView::Template.new("<ul><li>first</li><li>second</li><li>third</li></ul>",
|
78
|
+
"/path/to/file.erb",
|
79
|
+
ActionView::Template::Handlers::ERB,
|
80
|
+
{:virtual_path=>"posts/index", :format=>:html})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return modified source" do
|
84
|
+
@template.source.gsub("\n", "").should == "<ul><li>me first</li><li>first</li><li>second</li><li>third</li></ul>"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "with a single insert_bottom override defined" do
|
89
|
+
before(:all) do
|
90
|
+
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_bottom => "ul", :text => "<li>I'm always last</li>")
|
91
|
+
|
92
|
+
@template = ActionView::Template.new("<ul><li>first</li><li>second</li><li>third</li></ul>",
|
93
|
+
"/path/to/file.erb",
|
94
|
+
ActionView::Template::Handlers::ERB,
|
95
|
+
{:virtual_path=>"posts/index", :format=>:html})
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return modified source" do
|
99
|
+
@template.source.gsub("\n", "").should == "<ul><li>first</li><li>second</li><li>third</li><li>I'm always last</li></ul>"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
describe "with a single disabled override defined" do
|
105
|
+
before(:all) do
|
106
|
+
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>", :disabled => true)
|
107
|
+
@template = ActionView::Template.new("<p>test</p><%= raw(text) %>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return unmodified source" do
|
111
|
+
@template.source.should == "<p>test</p><%= raw(text) %>"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
73
115
|
end
|
74
116
|
end
|
75
117
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Quinn
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-04-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,7 @@ extensions: []
|
|
59
59
|
extra_rdoc_files:
|
60
60
|
- README.markdown
|
61
61
|
files:
|
62
|
+
- .gitignore
|
62
63
|
- MIT-LICENSE
|
63
64
|
- README.markdown
|
64
65
|
- Rakefile
|
@@ -69,8 +70,13 @@ files:
|
|
69
70
|
- lib/deface/action_view_extensions.rb
|
70
71
|
- lib/deface/override.rb
|
71
72
|
- lib/deface/parser.rb
|
73
|
+
- lib/deface/template_helper.rb
|
74
|
+
- spec/assets/admin/posts/index.html.erb
|
75
|
+
- spec/assets/shared/_post.html.erb
|
76
|
+
- spec/assets/shared/person.html.erb
|
72
77
|
- spec/deface/override_spec.rb
|
73
78
|
- spec/deface/parser_spec.rb
|
79
|
+
- spec/deface/template_helper_spec.rb
|
74
80
|
- spec/deface/template_spec.rb
|
75
81
|
- spec/spec_helper.rb
|
76
82
|
has_rdoc: true
|
@@ -103,12 +109,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
109
|
requirements: []
|
104
110
|
|
105
111
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.5.0
|
107
113
|
signing_key:
|
108
114
|
specification_version: 3
|
109
115
|
summary: Deface is a library that allows you to customize ERB views in Rails
|
110
116
|
test_files:
|
117
|
+
- spec/assets/admin/posts/index.html.erb
|
118
|
+
- spec/assets/shared/_post.html.erb
|
119
|
+
- spec/assets/shared/person.html.erb
|
111
120
|
- spec/deface/override_spec.rb
|
112
121
|
- spec/deface/parser_spec.rb
|
122
|
+
- spec/deface/template_helper_spec.rb
|
113
123
|
- spec/deface/template_spec.rb
|
114
124
|
- spec/spec_helper.rb
|