deface 0.6.0 → 0.6.1
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/README.markdown +10 -0
- data/deface.gemspec +1 -1
- data/lib/deface/override.rb +11 -1
- data/spec/deface/template_spec.rb +15 -0
- metadata +4 -4
data/README.markdown
CHANGED
@@ -33,6 +33,8 @@ Action
|
|
33
33
|
|
34
34
|
* <tt>:insert_bottom</tt> - Inserts inside all elements that match the supplied selector, as the last child.
|
35
35
|
|
36
|
+
* <tt>:set_attributes</tt> - Sets (or adds) attributes to all elements that match the supplied selector, expects :attributes option to be passed.
|
37
|
+
|
36
38
|
Source
|
37
39
|
------
|
38
40
|
* <tt>:text</tt> - String containing markup
|
@@ -57,6 +59,8 @@ Optional
|
|
57
59
|
the named override passed.
|
58
60
|
* <tt>:sequence => {:after => "*override_name*")</tt> - the current override will be applied after the named override passed.
|
59
61
|
|
62
|
+
* <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
|
63
|
+
|
60
64
|
Examples
|
61
65
|
========
|
62
66
|
|
@@ -88,6 +92,12 @@ Removes any ERB block containing the string `helper_method` in the `posts/new.ht
|
|
88
92
|
:remove => "code[erb-loud]:contains('helper_method')",
|
89
93
|
:original => "<%= helper_method %>")
|
90
94
|
|
95
|
+
Sets (or adds if not present) the `class` and `title` attributes to all instances of `a` with an id of `link` in `posts/index.html.erb`
|
96
|
+
|
97
|
+
Deface::Override.new(:virtual_path => 'posts/index',
|
98
|
+
:name => 'add_attrs_to_a_link',
|
99
|
+
:set_attributes => 'a#link',
|
100
|
+
:attributes => {:class => 'pretty', :title => 'This is a link'})
|
91
101
|
|
92
102
|
Implementation
|
93
103
|
==============
|
data/deface.gemspec
CHANGED
data/lib/deface/override.rb
CHANGED
@@ -6,7 +6,7 @@ module Deface
|
|
6
6
|
attr_accessor :args
|
7
7
|
|
8
8
|
@@all ||= {}
|
9
|
-
@@actions = [:remove, :replace, :insert_after, :insert_before, :insert_top, :insert_bottom]
|
9
|
+
@@actions = [:remove, :replace, :insert_after, :insert_before, :insert_top, :insert_bottom, :set_attributes]
|
10
10
|
|
11
11
|
# Initializes new override, you must supply only one Target, Action & Source
|
12
12
|
# parameter for each override (and any number of Optional parameters).
|
@@ -25,6 +25,7 @@ module Deface
|
|
25
25
|
# * <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
|
26
26
|
# * <tt>:insert_top</tt> - Inserts inside all elements that match the supplied selector, before all existing child
|
27
27
|
# * <tt>:insert_bottom</tt> - Inserts inside all elements that match the supplied selector, after all existing child
|
28
|
+
# * <tt>:set_attributes</tt> - Sets (or adds) attributes to all elements that match the supplied selector, expects :attributes option to be passed.
|
28
29
|
#
|
29
30
|
# ==== Source
|
30
31
|
#
|
@@ -49,6 +50,7 @@ module Deface
|
|
49
50
|
# same virutal_path, the current override will be appplied before
|
50
51
|
# the named override passed.
|
51
52
|
# :sequence => {:after => "override_name") - the current override will be applied after the named override passed.
|
53
|
+
# * <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
|
52
54
|
#
|
53
55
|
def initialize(args)
|
54
56
|
@args = args
|
@@ -152,6 +154,10 @@ module Deface
|
|
152
154
|
@args[:closing_selector]
|
153
155
|
end
|
154
156
|
|
157
|
+
def attributes
|
158
|
+
@args[:attributes] || []
|
159
|
+
end
|
160
|
+
|
155
161
|
# applies all applicable overrides to given source
|
156
162
|
#
|
157
163
|
def self.apply(source, details, log=true)
|
@@ -201,6 +207,10 @@ module Deface
|
|
201
207
|
match.children.before(override.source_element)
|
202
208
|
when :insert_bottom
|
203
209
|
match.children.after(override.source_element)
|
210
|
+
when :set_attributes
|
211
|
+
override.attributes.each do |name, value|
|
212
|
+
match.set_attribute(name.to_s, value.to_s)
|
213
|
+
end
|
204
214
|
end
|
205
215
|
|
206
216
|
end
|
@@ -121,6 +121,21 @@ module ActionView
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
describe "with a single set_attributes override defined" do
|
125
|
+
before(:all) do
|
126
|
+
Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :set_attributes => 'img',
|
127
|
+
:attributes => {:class => 'pretty', :alt => 'something interesting'})
|
128
|
+
|
129
|
+
@template = ActionView::Template.new("<div><img class=\"button\" src=\"path/to/button.png\"></div>",
|
130
|
+
"/path/to/file.erb",
|
131
|
+
ActionView::Template::Handlers::ERB,
|
132
|
+
{:virtual_path=>"posts/index", :format=>:html})
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return modified source" do
|
136
|
+
@template.source.gsub("\n", "").should == "<div><img class=\"pretty\" src=\"path/to/button.png\" alt=\"something interesting\"></div>"
|
137
|
+
end
|
138
|
+
end
|
124
139
|
|
125
140
|
describe "with a single disabled override defined" do
|
126
141
|
before(:all) do
|
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: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
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: 2011-07-
|
18
|
+
date: 2011-07-27 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|