deface 1.6.2 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d70515c1f6f72cef4d6b7d34d936e5fac929ddda6a896cbd9c0c30dddff8c19e
4
- data.tar.gz: e6950eb7f793b4111513744ddb48d7ad7a83a918a1f9b8850619b41c7864f515
3
+ metadata.gz: f95e0d9ff0d9928f8791253e4ce8a96e8c3dfda75505f1f6f9d96d5b50ee20cc
4
+ data.tar.gz: 5db5672c1fc4c8e43a591674a6d60950a6b70e48f54adbcb9d3f0a380ad2e039
5
5
  SHA512:
6
- metadata.gz: fd12b650a9104d57bc0b17c7a88324ff77008516e0fa789724f0622f59b26160050ac1eafa9dc42c73b51a93942ccb9c45902761e629f525fd32685a62afbdc9
7
- data.tar.gz: 4924e7dfd0a97adf3acebe4f4f15c5d3146e64aea5f75b9d64c0ac5746f9320678988d23af84b196ef30a2e8f1e4f1e8e37d546a5bad676fb12c6fecfc63e596
6
+ metadata.gz: 5b36c2c608cc51a7975a97da0931e351be90dc4a19d4c51bc37d3f5fe6a0023ed31a6b67ed01d6b17105ded32edf6b1d6cfd1a1bd538471a52790fbb526f1cf6
7
+ data.tar.gz: 8cf7a37e8af2c13cfcbdeaf039434fd8736e777ec7fb2a2ceeb7186b0a49e4d931c14459e882d71d5d10b527ab523f9f1d6500f452c6acb2b5746b6c015aa99b
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,45 @@
1
+ on:
2
+ - push
3
+ - pull_request
4
+
5
+ jobs:
6
+ build:
7
+ name: "ruby ${{ matrix.combo.ruby }} / ${{ matrix.combo.gemfile }}"
8
+ strategy:
9
+ matrix:
10
+ combo:
11
+ # TODO: re-enable commented combos and expand the matrix to Ruby 3.1 and Rails 7+
12
+
13
+ # - ruby: "3.0"
14
+ # gemfile: "rails_6_1"
15
+ # - ruby: "2.7"
16
+ # gemfile: "rails_6_1"
17
+ - ruby: "2.6"
18
+ gemfile: "rails_6_1"
19
+ - ruby: "2.5"
20
+ gemfile: "rails_6_1"
21
+
22
+ # - ruby: "2.7"
23
+ # gemfile: "rails_6_0"
24
+ - ruby: "2.6"
25
+ gemfile: "rails_6_0"
26
+ - ruby: "2.5"
27
+ gemfile: "rails_6_0"
28
+
29
+ - ruby: "2.5"
30
+ gemfile: "rails_5_2"
31
+
32
+ runs-on: ubuntu-latest
33
+
34
+ env:
35
+ GEMFILE_PATH: gemfiles/${{ matrix.combo.gemfile }}.gemfile
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+ - uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: ${{ matrix.combo.ruby }}
42
+ - name: Setup project
43
+ run: bin/setup
44
+ - name: Run test
45
+ run: "bundle exec rake"
data/Appraisals CHANGED
@@ -1,11 +1,26 @@
1
1
  appraise 'rails-5.2' do
2
- gem 'rails', '~> 5.2.0'
2
+ %w[
3
+ actionview
4
+ railties
5
+ ].each do |rails_gem|
6
+ gem rails_gem, '~> 5.2.0'
7
+ end
3
8
  end
4
9
 
5
10
  appraise 'rails-6.0' do
6
- gem 'rails', '~> 6.0.0'
11
+ %w[
12
+ actionview
13
+ railties
14
+ ].each do |rails_gem|
15
+ gem rails_gem, '~> 6.0.0'
16
+ end
7
17
  end
8
18
 
9
19
  appraise 'rails-6.1' do
10
- gem 'rails', '~> 6.1.0'
20
+ %w[
21
+ actionview
22
+ railties
23
+ ].each do |rails_gem|
24
+ gem rails_gem, '~> 6.1.0'
25
+ end
11
26
  end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,12 @@
1
+ # Contributing
2
+
3
+ ## Setup you development environment
4
+
5
+ 1. Clone the repo
6
+ 2. Run `bin/setup` to install dependencies
7
+ 3. Run `bin/sandbox` to (re)generate the sandbox application for local experiments
8
+
9
+ ## To run specs locally on the matrix of supported versions
10
+
11
+ 1. Run `bundle exec appraisal install`
12
+ 2. Run `bundle exec appraisal rake`
data/README.markdown CHANGED
@@ -1,41 +1,13 @@
1
- <p style="float:right;">
2
- <a href="http://secure.travis-ci.org/spree/deface">
3
- <img src="https://secure.travis-ci.org/spree/deface.svg?branch=master">
4
- </a>
5
- </p>
1
+ # Deface
6
2
 
7
- Deface
8
- ======
3
+ [![Travis build](https://secure.travis-ci.org/spree/deface.svg?branch=master)](https://travis-ci.com/github/spree/deface)
9
4
 
10
5
  Deface is a library that allows you to customize HTML (ERB, Haml and Slim) views in a Rails application without editing the underlying view.
11
6
 
12
7
  It allows you to easily target html & erb elements as the hooks for customization using CSS selectors as supported by Nokogiri.
13
8
 
14
9
 
15
- Upgrading from 0.9 to 1.0
16
- -------------------------
17
-
18
- If you are updating from 0.9.x to 1.0.0 or higher, there's a major internal change you should be aware of.
19
-
20
- Previously, erb blocks (i.e. <%= some_method %>) were converted as:
21
-
22
- ```html
23
- <code erb-loud> some_method </code>
24
- ```
25
- They are now converted to:
26
-
27
- ```html
28
- <erb loud> some_method </erb>
29
- ```
30
-
31
- This change will affect any Override that uses a selector that matches on `code` or `code[erb-loud]` or `code[erb-silent]` etc, they should be updated to `erb`, `erb[loud]` or `erb[silent]`, etc.
32
-
33
- Note: HAML & SLIM are preconverted to ERB before Deface parsers them, so the same conversions are happening there.
34
-
35
- See the [Implementation](#implementation) section below for more details.
36
-
37
- Usage
38
- -----
10
+ ## Usage
39
11
 
40
12
  There are two ways of using Deface:
41
13
 
@@ -46,10 +18,9 @@ Both methods are interoperable, so you can use a mix, and redefine overrides def
46
18
 
47
19
 
48
20
 
49
- Using Deface::Override
50
- ----------------------
21
+ ## Using Deface::Override
51
22
 
52
- A new instance of the Deface::Override class is initialized for each customization you wish to define. When initializing a new override you must supply only one Target, Action & Source parameter and any number of Optional parameters.
23
+ A new instance of the Deface::Override class is initialized for each customization you wish to define. When initializing a new override you must supply only one Target, Action & Source parameter and any number of Optional parameters.
53
24
 
54
25
  **Note:** the source parameter is not required when the ````:remove, :set_attributes, :add_to_attributes, :remove_from_attributes```` actions are specified.
55
26
 
@@ -59,77 +30,77 @@ You should save your overrides in the ````app/overrides````, normally one overri
59
30
 
60
31
  ### Target
61
32
 
62
- * <tt>:virtual_path</tt> - The template / partial / layout where the override should take effect eg: *"shared/_person"*, *"admin/posts/new"* this will apply to all controller actions that use the specified template.
33
+ * `:virtual_path` - The template / partial / layout where the override should take effect eg: *"shared/_person"*, *"admin/posts/new"* this will apply to all controller actions that use the specified template.
63
34
 
64
35
  ### Action
65
36
 
66
- * <tt>:remove</tt> - Removes all elements that match the supplied selector
37
+ * `:remove` - Removes all elements that match the supplied selector
67
38
 
68
- * <tt>:replace</tt> - Replaces all elements that match the supplied selector
39
+ * `:replace` - Replaces all elements that match the supplied selector
69
40
 
70
- * <tt>:replace_contents</tt> - Replaces the contents of all elements that match the supplied selector
41
+ * `:replace_contents` - Replaces the contents of all elements that match the supplied selector
71
42
 
72
- * <tt>:surround</tt> - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
43
+ * `:surround` - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
73
44
 
74
- * <tt>:surround_contents</tt> - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
45
+ * `:surround_contents` - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
75
46
 
76
- * <tt>:insert_after</tt> - Inserts after all elements that match the supplied selector
47
+ * `:insert_after` - Inserts after all elements that match the supplied selector
77
48
 
78
- * <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
49
+ * `:insert_before` - Inserts before all elements that match the supplied selector
79
50
 
80
- * <tt>:insert_top</tt> - Inserts inside all elements that match the supplied selector, as the first child.
51
+ * `:insert_top` - Inserts inside all elements that match the supplied selector, as the first child.
81
52
 
82
- * <tt>:insert_bottom</tt> - Inserts inside all elements that match the supplied selector, as the last child.
53
+ * `:insert_bottom` - Inserts inside all elements that match the supplied selector, as the last child.
83
54
 
84
- * <tt>:set_attributes</tt> - Sets attributes on all elements that match the supplied selector, replacing existing attribute value if present or adding if not. Expects :attributes option to be passed.
55
+ * `:set_attributes` - Sets attributes on all elements that match the supplied selector, replacing existing attribute value if present or adding if not. Expects :attributes option to be passed.
85
56
 
86
- * <tt>:add_to_attributes</tt> - Appends value to attributes on all elements that match the supplied selector, adds attribute if not present. Expects :attributes option to be passed.
57
+ * `:add_to_attributes` - Appends value to attributes on all elements that match the supplied selector, adds attribute if not present. Expects :attributes option to be passed.
87
58
 
88
- * <tt>:remove_from_attributes</tt> - Removes value from attributes on all elements that match the supplied selector. Expects :attributes option to be passed.
59
+ * `:remove_from_attributes` - Removes value from attributes on all elements that match the supplied selector. Expects :attributes option to be passed.
89
60
 
90
61
  ### Source
91
62
 
92
- * <tt>:text</tt> - String containing markup
63
+ * `:text` - String containing markup
93
64
 
94
- * <tt>:partial</tt> - Relative path to a partial
65
+ * `:partial` - Relative path to a partial
95
66
 
96
- * <tt>:template</tt> - Relative path to a template
67
+ * `:template` - Relative path to a template
97
68
 
98
- * <tt>:cut</tt> - Cuts (i.e. copies and removes) an element or a range of elements from the current template as the source, using css selector(s). Supports two versions:
99
- * <tt>selector</tt> - A single string css selector (first match is used).
100
- * <tt>{:start => 'selector_a', :end => 'selector_b'}</tt> - select a range of elements using :start and :end css selectors. The end element must be a sibling of the first/starting element.
69
+ * `:cut` - Cuts (i.e. copies and removes) an element or a range of elements from the current template as the source, using css selector(s). Supports two versions:
70
+ * `selector` - A single string css selector (first match is used).
71
+ * `{:start => 'selector_a', :end => 'selector_b'}` - select a range of elements using :start and :end css selectors. The end element must be a sibling of the first/starting element.
101
72
 
102
- * <tt>:copy</tt> - Copies an element or a range of elements from the current template as the source, using css selector(s). Supports two versions:
103
- * <tt>selector</tt> - A single string css selector (first match is used).
104
- * <tt>{:start => 'selector_a', :end => 'selector_b'}</tt> - select a range of elements using :start and :end css selectors. The end element must be a sibling of the first/starting element.
73
+ * `:copy` - Copies an element or a range of elements from the current template as the source, using css selector(s). Supports two versions:
74
+ * `selector` - A single string css selector (first match is used).
75
+ * `{:start => 'selector_a', :end => 'selector_b'}` - select a range of elements using :start and :end css selectors. The end element must be a sibling of the first/starting element.
105
76
 
106
77
  ### Optional
107
78
 
108
- * <tt>:name</tt> - Unique name for override so it can be identified and modified later. This needs to be unique within the same `:virtual_path`
79
+ * `:name` - Unique name for override so it can be identified and modified later. This needs to be unique within the same `:virtual_path`
109
80
 
110
- * <tt>:disabled</tt> - When set to true the override will not be applied.
81
+ * `:disabled` - When set to true the override will not be applied.
111
82
 
112
- * <tt>:original</tt> - Either a string containing the original markup that is being overridden, or a string that is the SHA1 digest of the original markup. If supplied Deface will log when the original markup changes, which helps highlight overrides that need attention when upgrading versions of the source application. Only really warranted for :replace overrides. NB: All whitespace is stripped before comparison. To generate the SHA1 digest do: `Digest::SHA1.hexdigest(original_markup_string.gsub(/\s/, ''))`
83
+ * `:original` - Either a string containing the original markup that is being overridden, or a string that is the SHA1 digest of the original markup. If supplied Deface will log when the original markup changes, which helps highlight overrides that need attention when upgrading versions of the source application. Only really warranted for :replace overrides. NB: All whitespace is stripped before comparison. To generate the SHA1 digest do: `Digest::SHA1.hexdigest(original_markup_string.gsub(/\s/, ''))`
113
84
 
114
- * <tt>:closing_selector</tt> - A second css selector targeting an end element, allowing you to select a range of elements to apply an action against. The :closing_selector only supports the :replace, :remove and :replace_contents actions, and the end element must be a sibling of the first/starting element. Note the CSS general sibling selector (~) is used to match the first element after the opening selector (see below for an example).
85
+ * `:closing_selector` - A second css selector targeting an end element, allowing you to select a range of elements to apply an action against. The :closing_selector only supports the :replace, :remove and :replace_contents actions, and the end element must be a sibling of the first/starting element. Note the CSS general sibling selector (~) is used to match the first element after the opening selector (see below for an example).
115
86
 
116
- * <tt>:sequence</tt> - Used to order the application of an override for a specific virtual path, helpful when an override depends on another override being applied first, supports:
117
- * <tt>:sequence => n</tt> - where n is a positive or negative integer (lower numbers get applied first, default 100).
118
- * <tt>:sequence => {:before => "*override_name*"}</tt> - where "*override_name*" is the name of an override defined for the
119
- same virtual_path, the current override will be appplied before
87
+ * `:sequence` - Used to order the application of an override for a specific virtual path, helpful when an override depends on another override being applied first, supports:
88
+ * `:sequence => n` - where n is a positive or negative integer (lower numbers get applied first, default 100).
89
+ * `:sequence => {:before => "*override_name*"}` - where "*override_name*" is the name of an override defined for the
90
+ same virtual_path, the current override will be appplied before
120
91
  the named override passed.
121
- * <tt>:sequence => {:after => "*override_name*"}</tt> - the current override will be applied after the named override passed.
92
+ * `:sequence => {:after => "*override_name*"}` - the current override will be applied after the named override passed.
122
93
 
123
- * <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
94
+ * `:attributes` - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
124
95
 
125
96
  ### Examples
126
97
 
127
98
  Replaces all instances of `h1` in the `posts/_form.html.erb` partial with `<h1>New Post</h1>`
128
99
 
129
100
  ```ruby
130
- Deface::Override.new(:virtual_path => "posts/_form",
131
- :name => "example-1",
132
- :replace => "h1",
101
+ Deface::Override.new(:virtual_path => "posts/_form",
102
+ :name => "example-1",
103
+ :replace => "h1",
133
104
  :text => "<h1>New Post</h1>")
134
105
  ```
135
106
 
@@ -146,8 +117,8 @@ end
146
117
  Inserts `<%= link_to "List Comments", comments_url(post) %>` before all instances of `p` with css class `comment` in `posts/index.html.erb`
147
118
 
148
119
  ```ruby
149
- Deface::Override.new(:virtual_path => "posts/index",
150
- :name => "example-2",
120
+ Deface::Override.new(:virtual_path => "posts/index",
121
+ :name => "example-2",
151
122
  :insert_before => "p.comment",
152
123
  :text => "<%= link_to 'List Comments', comments_url(post) %>")
153
124
  ```
@@ -155,17 +126,17 @@ Deface::Override.new(:virtual_path => "posts/index",
155
126
  Inserts the contents of `shared/_comment.html.erb` after all instances of `div` with an id of `comment_21` in `posts/show.html.erb`
156
127
 
157
128
  ```ruby
158
- Deface::Override.new(:virtual_path => "posts/show",
129
+ Deface::Override.new(:virtual_path => "posts/show",
159
130
  :name => "example-3",
160
- :insert_after => "div#comment_21",
131
+ :insert_after => "div#comment_21",
161
132
  :partial => "shared/comment")
162
133
  ```
163
134
 
164
135
  Removes any ERB block containing the string `helper_method` in the `posts/new.html.erb` template, will also log if markup being removed does not exactly match `<%= helper_method %>`
165
136
 
166
137
  ```ruby
167
- Deface::Override.new(:virtual_path => "posts/new",
168
- :name => "example-4",
138
+ Deface::Override.new(:virtual_path => "posts/new",
139
+ :name => "example-4",
169
140
  :remove => "erb[loud]:contains('helper_method')",
170
141
  :original => "<%= helper_method %>")
171
142
  ```
@@ -173,13 +144,13 @@ Deface::Override.new(:virtual_path => "posts/new",
173
144
  Wraps the `div` with id of `products` in ruby if statement, the <%= render_original %> in the `text` indicates where the matching content should be re-included.
174
145
 
175
146
  ```ruby
176
- Deface::Override.new(:virtual_path => "posts/new",
177
- :name => "example-5",
147
+ Deface::Override.new(:virtual_path => "posts/new",
148
+ :name => "example-5",
178
149
  :surround => "div#products",
179
150
  :text => "<% if @product.present? %><%= render_original %><% end %>")
180
151
  ```
181
152
 
182
- 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`
153
+ 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`
183
154
 
184
155
  ```ruby
185
156
  Deface::Override.new(:virtual_path => 'posts/index',
@@ -203,7 +174,7 @@ Deface scopes overrides by virtual_path (or partial / template file), that means
203
174
 
204
175
  ### Redefining Overrides
205
176
 
206
- You can redefine an existing override by simply declaring a new override with the same <tt>:virtual_path</tt>, <tt>:name</tt> and [action](#action) that was originally used.
177
+ You can redefine an existing override by simply declaring a new override with the same `:virtual_path`, `:name` and [action](#action) that was originally used.
207
178
  You do not need to resupply all the values originally used, just the ones you want to change:
208
179
 
209
180
  ```ruby
@@ -231,8 +202,7 @@ This can also be activated globally for all DSL overrides in your app's `applica
231
202
  config.deface.namespaced = true # default is false
232
203
  ```
233
204
 
234
- Using the Deface DSL (.deface files)
235
- ------------------------------------
205
+ ## Using the Deface DSL (.deface files)
236
206
 
237
207
  Instead of defining Deface::Override instances directly, you can alternatively add `.deface` files to the `app/overrides` folder and Deface will automatically pick them up.
238
208
  The path of each override should match the path of the view template you want to modify, say for example if you have a template at:
@@ -267,7 +237,7 @@ and including haml source:
267
237
  You can include all the additional options you can normally use when defining a Deface::Override manually, a more complex example:
268
238
 
269
239
  ```html
270
- <!-- replace_contents 'h1' closing_selector 'div#intro'
240
+ <!-- replace_contents 'h1' closing_selector 'div#intro'
271
241
  sequence :before => 'my_other_override'
272
242
  disabled -->
273
243
  <p>This is a complicated example</p>
@@ -290,21 +260,22 @@ or
290
260
 
291
261
  #### Namespacing
292
262
 
293
- When using the DSL, overrides automatically take their name from the filename of the file in which they are defined
294
- (ie `my_override.html.erb.deface` becomes `my_override`) so overrides with the same filename will replace each other,
263
+ When using the DSL, overrides automatically take their name from the filename of the file in which they are defined
264
+ (ie `my_override.html.erb.deface` becomes `my_override`) so overrides with the same filename will replace each other,
295
265
  even if they are defined in separate engines. If you want to avoid this, you can use the `namespaced` option :
296
266
 
297
267
  ```erb
298
268
  <!-- insert_bottom 'head' namespaced -->
299
269
  ```
270
+
300
271
  or activate it globally for all DSL overrides in your app's `application.rb` file:
301
272
 
302
273
  ```ruby
303
274
  config.deface.namespaced = true # default is false
304
275
  ```
305
276
 
306
- Each override will then have its name namespaced to the engine in which it was defined
307
- (ie `my_override.html.erb.deface` defined in `MyEngine` becomes `my_engine_my_override`),
277
+ Each override will then have its name namespaced to the engine in which it was defined
278
+ (ie `my_override.html.erb.deface` defined in `MyEngine` becomes `my_engine_my_override`),
308
279
  allowing overrides in different engines with identical filenames to co-exist.
309
280
 
310
281
  ### DSL usage for overrides that do not include markup
@@ -323,29 +294,27 @@ attributes :alt => 'Click here to search'
323
294
  ```
324
295
 
325
296
 
326
- Rake Tasks
327
- ----------
297
+ ## Rake Tasks
328
298
 
329
299
  Deface includes a couple of rake tasks that can be helpful when defining or debugging overrides.
330
300
 
331
- **deface:get_result** - Will list the original contents of a partial or template, the overrides that have been defined for a that file, and the resulting markup. *get_result* takes a single argument which is the virtual path of the template / partial:
301
+ `rake deface:get_result` - Will list the original contents of a partial or template, the overrides that have been defined for a that file, and the resulting markup. *get_result* takes a single argument which is the virtual path of the template / partial:
332
302
 
333
303
  rake deface:get_result[shared/_head]
334
304
 
335
305
  rake deface:get_result['admin/products/index']
336
306
 
337
- **deface:test_selector** - Applies a given CSS selector against a partial or template and outputs the markup for each match (if any). *test_selector* requires two arguments, the first is the virtual_path for the partial / template, the second is the CSS selector to apply:
307
+ `rake deface:test_selector` - Applies a given CSS selector against a partial or template and outputs the markup for each match (if any). *test_selector* requires two arguments, the first is the virtual_path for the partial / template, the second is the CSS selector to apply:
338
308
 
339
309
  rake deface:test_selector[shared/_head,title]
340
310
 
341
311
  rake deface:test_selector['admin/products/index','div.toolbar']
342
312
 
343
- **deface:precompile** - Generates compiled views that contain all overrides applied. See `Production & Precompiling` section below for more.
313
+ `rake deface:precompile` - Generates compiled views that contain all overrides applied. See `Production & Precompiling` section below for more.
344
314
 
345
315
  rake deface:precompile
346
316
 
347
- Production & Precompiling
348
- -------------------------
317
+ ## Production & Precompiling
349
318
 
350
319
  Deface now supports precompiling where all overrides are loaded and applied to the original views and the resulting templates are then saved to your application's `app/compiled_views` directory. To precompile run:
351
320
 
@@ -380,19 +349,34 @@ end
380
349
  after 'deploy:updated', 'deface:precompile'
381
350
  ```
382
351
 
352
+ ## Upgrading from 0.9 to 1.0
353
+
354
+ If you are updating from 0.9.x to 1.0.0 or higher, there's a major internal change you should be aware of.
355
+
356
+ Previously, erb blocks (i.e. <%= some_method %>) were converted as:
357
+
358
+ ```html
359
+ <code erb-loud> some_method </code>
360
+ ```
361
+ They are now converted to:
362
+
363
+ ```html
364
+ <erb loud> some_method </erb>
365
+ ```
366
+
367
+ This change will affect any Override that uses a selector that matches on `code` or `code[erb-loud]` or `code[erb-silent]` etc, they should be updated to `erb`, `erb[loud]` or `erb[silent]`, etc.
383
368
 
384
- Demo & Testing
385
- --------------
386
- You can play with Deface and see its parsing in action at [deface.heroku.com](http://deface.heroku.com)
369
+ Note: HAML & SLIM are preconverted to ERB before Deface parsers them, so the same conversions are happening there.
370
+
371
+ See the [Implementation](#implementation) section below for more details.
387
372
 
388
373
 
389
- Implementation
390
- ==============
374
+ # Implementation
391
375
 
392
- Deface temporarily converts ERB files into a pseudo HTML markup that can be parsed and queired by Nokogiri, using the following approach:
376
+ Deface temporarily converts ERB files into a pseudo HTML markup that can be parsed and queried by Nokogiri, using the following approach:
393
377
 
394
378
  ```erb
395
- <%= some ruby code %>
379
+ <%= some ruby code %>
396
380
  ```
397
381
 
398
382
  becomes:
@@ -401,8 +385,8 @@ becomes:
401
385
  <erb loud> some ruby code </erb>
402
386
  ```
403
387
 
404
- and
405
-
388
+ and
389
+
406
390
  ```erb
407
391
  <% other ruby code %>
408
392
  ```
@@ -418,7 +402,7 @@ ERB that is contained inside a HTML tag definition is converted slightly differe
418
402
  ```erb
419
403
  <p id="<%= dom_id @product %>" <%= "style='display:block';" %>>
420
404
  ```
421
-
405
+
422
406
  becomes:
423
407
 
424
408
  ```html
@@ -428,8 +412,8 @@ becomes:
428
412
  Deface overrides have full access to all variables accessible to the view being customized.
429
413
 
430
414
 
431
- Caveats
432
- ======
415
+ # Caveats
416
+
433
417
  Deface uses the amazing Nokogiri library (and in turn libxml) for parsing HTML / view files, in some circumstances either Deface's own pre-parser or libxml's will fail to correctly parse a template. You can avoid such issues by ensuring your templates contain valid HTML. Some other caveats include:
434
418
 
435
419
  1. Ensure that your layout views include doctype, html, head and body tags in a single file, as Nokogiri will create such elements if it detects any of these tags have been incorrectly nested.
data/Rakefile CHANGED
@@ -5,8 +5,12 @@ require 'rdoc/task'
5
5
  require 'rspec'
6
6
  require 'rspec/core/rake_task'
7
7
 
8
+ require 'bundler'
9
+ Bundler.require
10
+ Bundler::GemHelper.install_tasks
11
+
8
12
  desc 'Default: run specs'
9
- task :default => :spec
13
+ task :default => :spec
10
14
  RSpec::Core::RakeTask.new do |t|
11
15
  t.pattern = "spec/**/*_spec.rb"
12
16
  end
data/bin/sandbox CHANGED
@@ -26,6 +26,8 @@ fi
26
26
  cd ./sandbox
27
27
  cat <<RUBY >> Gemfile
28
28
  gem '$gem_name', path: '..'
29
+ gem 'haml'
30
+ gem 'slim'
29
31
  RUBY
30
32
 
31
33
  unbundled bundle install --gemfile Gemfile
data/bin/sandbox-setup CHANGED
@@ -1,24 +1,89 @@
1
- #!/usr/bin/env bash
2
-
3
- bin/rails g scaffold Post title body
4
- bin/rails db:migrate
5
-
6
- mkdir sandbox/app/overrides
7
-
8
- echo <<RUBY >> sandbox/app/overrides/sparkling_title.rb
9
- Deface::Override.new(
10
- virtual_path: "posts/show",
11
- name: "sparkling_title",
12
- replace: 'p:nth-child(2)',
13
- text: "<h1>✨<%= @post.title %>✨</h1>"
14
- )
15
-
16
- Deface::Override.new(
17
- virtual_path: "posts/show",
18
- name: "sparkling_body",
19
- replace: 'p:nth-child(3)',
20
- text: "<p style='border:2px gray solid; padding: 1rem;'><%= @post.body %></p>"
21
- )
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ extend FileUtils
5
+
6
+ system 'bin/rails g scaffold Post title body'
7
+ system 'bin/rails db:migrate'
8
+
9
+ mkdir_p 'sandbox/app/overrides'
10
+
11
+ File.write 'sandbox/app/views/posts/_haml_partial.html.haml', <<~HAML
12
+ %h2 hello from haml
13
+ HAML
14
+
15
+ File.write 'sandbox/app/views/posts/_slim_partial.html.slim', <<~SLIM
16
+ h2 hello from slim
17
+ SLIM
18
+
19
+ File.write 'sandbox/app/views/posts/_haml_defaced_partial.html.haml', <<~HAML
20
+ %h3 hello from defaced haml
21
+ HAML
22
+
23
+ File.write 'sandbox/app/views/posts/_slim_defaced_partial.html.slim', <<~SLIM
24
+ h3 hello from defaced slim
25
+ SLIM
26
+
27
+ File.write 'sandbox/app/overrides/improved_posts.rb', <<~RUBY
28
+ Deface::Override.new(
29
+ virtual_path: "posts/show",
30
+ name: "sparkling_post_title",
31
+ replace: 'p:nth-child(2)',
32
+ text: "<h1>✨<%= @post.title %>✨</h1>"
33
+ )
34
+
35
+ Deface::Override.new(
36
+ virtual_path: "posts/show",
37
+ name: "modern_style_post_body",
38
+ replace: 'p:nth-child(3)',
39
+ text: "<p style='border:2px gray solid; padding: 1rem;'><%= @post.body %></p>"
40
+ )
41
+
42
+ Deface::Override.new(
43
+ virtual_path: "posts/index",
44
+ name: "sparkling_posts_title",
45
+ replace: 'tr td:first-child',
46
+ text: "<td>✨<%= post.title %>✨</td>"
47
+ )
48
+
49
+ Deface::Override.new(
50
+ virtual_path: "posts/index",
51
+ name: "modern_style_post_body",
52
+ replace: 'tr td:nth-child(2)',
53
+ text: "<td style='border:2px gray solid; padding: 1rem;'><%= post.body %></d>"
54
+ )
55
+
56
+ Deface::Override.new(
57
+ virtual_path: "posts/index",
58
+ name: "haml_and_slim_partials",
59
+ insert_before: 'table',
60
+ text: "
61
+ <header><%= render 'haml_partial' %><%= render 'slim_partial' %></header>
62
+ <section><%= render 'haml_defaced_partial' %><%= render 'slim_defaced_partial' %></section>
63
+ "
64
+ )
65
+
66
+ Deface::Override.new(
67
+ virtual_path: "posts/_haml_defaced_partial",
68
+ name: "haml_deface",
69
+ insert_before: 'h3',
70
+ text: "<h4>HAML subtitle</h4>"
71
+ )
72
+
73
+ Deface::Override.new(
74
+ virtual_path: "posts/_slim_defaced_partial",
75
+ name: "slim_deface",
76
+ insert_before: 'h3',
77
+ text: "<h4>SLIM subtitle</h4>"
78
+ )
79
+ RUBY
80
+
81
+ File.write 'sandbox/config/routes.rb', <<~RUBY
82
+ Rails.application.routes.draw do
83
+ resources :posts
84
+ root to: "posts#index"
85
+ end
22
86
  RUBY
23
87
 
24
- bin/rails runner "Post.create(title: 'Foo', body: 'Bar '*10)"
88
+ system "bin/rails", "runner", "Post.create(title: 'Foo', body: 'Bar '*10)"
89
+ system "bin/rails", "runner", "Post.create(title: 'Baz', body: 'Boz '*10)"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/deface.gemspec CHANGED
@@ -30,7 +30,13 @@ Gem::Specification.new do |spec|
30
30
  spec.extra_rdoc_files = ["README.markdown"]
31
31
 
32
32
  spec.add_dependency('nokogiri', '>= 1.6')
33
- spec.add_dependency('rails', '>= 5.2')
33
+
34
+ %w[
35
+ actionview
36
+ railties
37
+ ].each do |rails_gem|
38
+ spec.add_dependency(rails_gem, '>= 5.2')
39
+ end
34
40
  spec.add_dependency('rainbow', '>= 2.1.0')
35
41
  spec.add_dependency('polyglot')
36
42
 
@@ -39,7 +45,7 @@ Gem::Specification.new do |spec|
39
45
  spec.add_development_dependency('gem-release')
40
46
  spec.add_development_dependency('rspec', '>= 3.1.0')
41
47
  spec.add_development_dependency('haml', ['>= 4.0', '< 6'])
42
- spec.add_development_dependency('slim', '~> 3.0')
48
+ spec.add_development_dependency('slim', '~> 4.1')
43
49
  spec.add_development_dependency('simplecov', '>= 0.6.4')
44
50
  spec.add_development_dependency('generator_spec', '~> 0.8')
45
51
  spec.add_development_dependency('pry')
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.2.0"
5
+ gem "actionview", "~> 5.2.0"
6
+ gem "railties", "~> 5.2.0"
6
7
 
7
8
  group :test do
8
9
  gem "test-unit"
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0"
5
+ gem "actionview", "~> 6.0.0"
6
+ gem "railties", "~> 6.0.0"
6
7
 
7
8
  group :test do
8
9
  gem "test-unit"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionview", "~> 6.1.0"
6
+ gem "railties", "~> 6.1.0"
7
+
8
+ group :test do
9
+ gem "test-unit"
10
+ gem "pry"
11
+ gem "pry-byebug"
12
+ end
13
+
14
+ gemspec path: "../"
@@ -2,7 +2,12 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.1.0"
5
+ %w[
6
+ actionview
7
+ railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, "~> 6.1.0"
10
+ end
6
11
 
7
12
  group :test do
8
13
  gem "test-unit"
@@ -14,46 +14,56 @@ module Deface::ActionViewExtensions
14
14
  end
15
15
 
16
16
  module DefacedTemplate
17
- def initialize(source, identifier, handler, details)
18
- syntax = Deface::ActionViewExtensions.determine_syntax(handler)
17
+ def encode!
18
+ return super unless Rails.application.config.deface.enabled
19
19
 
20
- if syntax
21
- processed_source = Deface::Override.apply(source.to_param, details, true, syntax)
20
+ # Before Rails 6 encode! returns nil
21
+ source = Deface.before_rails_6? ? (super; @source) : super
22
+ syntax = Deface::ActionViewExtensions.determine_syntax(@handler)
23
+ overrides = Deface::Override.find(
24
+ locals: @locals,
25
+ format: @format,
26
+ variant: @variant,
27
+ virtual_path: @virtual_path,
28
+ )
22
29
 
23
- # force change in handler before continuing to original Rails method
24
- # as we've just converted some other template language into ERB!
25
- #
26
- if [:slim, :haml].include?(syntax) && processed_source != source.to_param
27
- handler = ActionView::Template::Handlers::ERB
30
+ if syntax && overrides.any?
31
+ # Prevents any caching by rails in development mode.
32
+ @updated_at = Time.now if Deface.before_rails_6?
33
+ @handler = ActionView::Template::Handlers::ERB
34
+
35
+ # Modify the existing string instead of returning a copy
36
+ new_source = Deface::Override.apply_overrides(
37
+ Deface::Override.convert_source(source, syntax: syntax),
38
+ overrides: overrides
39
+ )
40
+
41
+ if Deface.before_rails_6?
42
+ @source.replace new_source
43
+ else
44
+ source.replace new_source
28
45
  end
29
- else
30
- processed_source = source.to_param
31
46
  end
32
47
 
33
- super(processed_source, identifier, handler, **details)
48
+ source
34
49
  end
35
50
 
36
- # refresh view to get source again if
37
- # view needs to be recompiled
38
- #
39
- def render(view, locals, buffer=nil, &block)
40
- mod = view.is_a?(Deface.template_class) ? Deface.template_class : view.singleton_class
51
+ private
41
52
 
42
- if @compiled && !mod.instance_methods.include?(method_name.to_sym)
43
- @compiled = false
44
- @source = refresh(view).source if respond_to?(:refresh)
45
- end
46
- buffer.nil? ? super(view, locals, buffer, &block) : super(view, locals, **buffer, &block)
47
- end
53
+ def compile!(view)
54
+ return super unless Rails.application.config.deface.enabled
48
55
 
49
- # inject deface hash into compiled view method name
50
- # used to determine if recompilation is needed
51
- #
52
- def method_name
53
- deface_hash = Deface::Override.digest(:virtual_path => @virtual_path)
56
+ @compile_mutex.synchronize do
57
+ current_deface_hash = Deface::Override.digest(virtual_path: @virtual_path)
58
+ @deface_hash = current_deface_hash if @deface_hash.nil?
54
59
 
55
- #we digest the whole method name as if it gets too long there's problems
56
- "_#{Deface::Digest.hexdigest("#{deface_hash}_#{super}")}"
60
+ if @deface_hash != current_deface_hash
61
+ @compiled = nil
62
+ @deface_hash = current_deface_hash
63
+ end
64
+ end
65
+
66
+ super
57
67
  end
58
68
 
59
69
  ActionView::Template.prepend self
@@ -6,58 +6,70 @@ module Deface
6
6
  def apply(source, details, log=true, syntax=:erb)
7
7
  overrides = find(details)
8
8
 
9
- if log && overrides.size > 0
10
- Rails.logger.debug "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for '#{details[:virtual_path]}'"
11
- end
9
+ return source if overrides.empty?
12
10
 
13
- unless overrides.empty?
14
- case syntax
15
- when :haml
16
- #convert haml to erb before parsing before
17
- source = Deface::HamlConverter.new(source.to_param).result
18
- when :slim
19
- source = Deface::SlimConverter.new(source.to_param).result
20
- end
11
+ Rails.logger.debug "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for '#{details[:virtual_path]}'" if log
21
12
 
22
- doc = Deface::Parser.convert(source)
13
+ apply_overrides(
14
+ convert_source(source, syntax: syntax),
15
+ overrides: overrides,
16
+ log: log
17
+ )
18
+ end
23
19
 
24
- overrides.each do |override|
25
- if override.disabled?
26
- Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log
27
- next
28
- end
20
+ # applies specified overrides to given source
21
+ def apply_overrides(source, overrides:, log: true)
29
22
 
30
- override.parsed_document = doc
31
- matches = override.matcher.matches(doc, log)
23
+ doc = Deface::Parser.convert(source)
32
24
 
33
- if log
34
- Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'")
25
+ overrides.each do |override|
26
+ if override.disabled?
27
+ Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log
28
+ next
29
+ end
35
30
 
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
41
- end
31
+ override.parsed_document = doc
32
+ matches = override.matcher.matches(doc, log)
33
+
34
+ if log
35
+ Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'")
42
36
 
43
- if matches.empty?
44
- override.failure = "failed to match :#{override.action} selector '#{override.selector}'"
45
- else
46
- override.failure = nil
47
- matches.each {|match| override.execute_action match }
37
+ # temporarily check and notify on use of old selector styles.
38
+ #
39
+ if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/)
40
+ 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>"
48
41
  end
49
42
  end
50
43
 
51
- # Prevents any caching by rails in development mode.
52
- details[:updated_at] = Time.now if Deface.before_rails_6?
44
+ if matches.empty?
45
+ override.failure = "failed to match :#{override.action} selector '#{override.selector}'"
46
+ else
47
+ override.failure = nil
48
+ matches.each {|match| override.execute_action match }
49
+ end
50
+ end
53
51
 
54
- source = doc.to_s
52
+ source = doc.to_s
55
53
 
56
- Deface::Parser.undo_erb_markup!(source)
57
- end
54
+ Deface::Parser.undo_erb_markup!(source)
58
55
 
59
56
  source
60
57
  end
58
+
59
+ # converts the source to a supported syntax (ERB)
60
+ def convert_source(source, syntax:)
61
+ # convert haml/slim to erb before parsing before
62
+ case syntax
63
+ when :erb
64
+ source
65
+ when :haml
66
+ Deface::HamlConverter.new(source.to_s).result
67
+ when :slim
68
+ Deface::SlimConverter.new(source.to_s).result
69
+ else
70
+ raise "unsupported syntax: #{syntax}"
71
+ end
72
+ end
61
73
  end
62
74
 
63
75
  def execute_action(target_element)
@@ -1,32 +1,58 @@
1
1
  module Deface
2
2
  module TemplateHelper
3
+ def self.lookup_context
4
+ @lookup_context ||= ActionView::LookupContext.new(
5
+ ActionController::Base.view_paths, {:formats => [:html]}
6
+ )
7
+ end
3
8
 
4
9
  # used to find source for a partial or template using virtual_path
5
- def load_template_source(virtual_path, partial, apply_overrides=true)
10
+ def load_template_source(virtual_path, partial, apply_overrides=true, lookup_context: Deface::TemplateHelper.lookup_context)
6
11
  parts = virtual_path.split("/")
7
- prefix = []
12
+
8
13
  if parts.size == 2
9
- prefix << ""
14
+ prefix = ""
10
15
  name = virtual_path
11
16
  else
12
- prefix << parts.shift
17
+ prefix = parts.shift
13
18
  name = parts.join("/")
14
19
  end
15
20
 
16
- #this needs to be reviewed for production mode, overrides not present
17
- Rails.application.config.deface.enabled = apply_overrides
18
- @lookup_context ||= ActionView::LookupContext.new(ActionController::Base.view_paths, {:formats => [:html]})
19
- view = @lookup_context.disable_cache do
20
- @lookup_context.find(name, prefix, partial)
21
- end
21
+ view = lookup_context.disable_cache { lookup_context.find(name, [prefix], partial) }
22
22
 
23
- if view.handler.to_s == "Haml::Plugin"
24
- Deface::HamlConverter.new(view.source).result
25
- elsif view.handler.class.to_s == "Slim::RailsTemplate"
26
- Deface::SlimConverter.new(view.source).result
27
- else
28
- view.source
23
+ source =
24
+ if view.handler.to_s == "Haml::Plugin"
25
+ Deface::HamlConverter.new(view.source).result
26
+ elsif view.handler.class.to_s == "Slim::RailsTemplate"
27
+ Deface::SlimConverter.new(view.source).result
28
+ else
29
+ view.source
30
+ end
31
+
32
+ if apply_overrides
33
+ begin
34
+ # This needs to be reviewed for production mode, overrides not present
35
+ original_enabled = Rails.application.config.deface.enabled
36
+ Rails.application.config.deface.enabled = apply_overrides
37
+
38
+ syntax = Deface::ActionViewExtensions.determine_syntax(view.handler)
39
+ overrides = Deface::Override.find(
40
+ locals: view.instance_variable_get(:@locals),
41
+ format: view.instance_variable_get(:@format),
42
+ variant: view.instance_variable_get(:@variant),
43
+ virtual_path: view.instance_variable_get(:@virtual_path),
44
+ )
45
+
46
+ if syntax && overrides.any?
47
+ source = Deface::Override.convert_source(source, syntax: syntax)
48
+ source = Deface::Override.apply_overrides(source, overrides: overrides)
49
+ end
50
+ ensure
51
+ Rails.application.config.deface.enabled = original_enabled
52
+ end
29
53
  end
54
+
55
+ source
30
56
  end
31
57
 
32
58
  #gets source erb for an element
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deface
4
- VERSION = '1.6.2'
4
+ VERSION = '1.8.2'
5
5
 
6
6
  def gem_version
7
7
  Gem::Version.new(VERSION)
@@ -3,8 +3,12 @@ require 'spec_helper'
3
3
  describe Deface::ActionViewExtensions do
4
4
  include_context "mock Rails.application"
5
5
 
6
- before supports_updated_at: true do
7
- skip "Current Rails doesn't support the updated_at attribute on ActionView" unless supports_updated_at?
6
+ before after_rails_6: true do
7
+ skip "This spec is targeted at Rails v6+" if Deface.before_rails_6?
8
+ end
9
+
10
+ before before_rails_6: true do
11
+ skip "This spec is targeted at Rails before v6+" unless Deface.before_rails_6?
8
12
  end
9
13
 
10
14
  let(:template) { ActionView::Template.new(
@@ -12,7 +16,7 @@ describe Deface::ActionViewExtensions do
12
16
  path,
13
17
  handler,
14
18
  **options,
15
- **(supports_updated_at? ? {updated_at: updated_at} : {})
19
+ **(Deface.before_rails_6? ? {updated_at: updated_at} : {})
16
20
  ) }
17
21
 
18
22
  let(:source) { "<p>test</p>" }
@@ -26,7 +30,6 @@ describe Deface::ActionViewExtensions do
26
30
  let(:format) { :html }
27
31
  let(:virtual_path) { "posts/index" }
28
32
 
29
- let(:supports_updated_at?) { Deface.before_rails_6? }
30
33
  let(:updated_at) { Time.now - 600 }
31
34
 
32
35
  describe "with no overrides defined" do
@@ -38,46 +41,12 @@ describe Deface::ActionViewExtensions do
38
41
  expect(template.source).to eq("<p>test</p>")
39
42
  end
40
43
 
41
- it "should not change updated_at", :supports_updated_at do
44
+ it "should not change updated_at", :before_rails_6 do
42
45
  expect(template.updated_at).to eq(updated_at)
43
46
  end
44
47
  end
45
48
 
46
- describe "with a single remove override defined" do
47
- let(:updated_at) { Time.now - 300 }
48
- let(:source) { "<p>test</p><%= raw(text) %>" }
49
-
50
- before do
51
- Deface::Override.new(virtual_path: "posts/index", name: "Posts#index", remove: "p", text: "<h1>Argh!</h1>")
52
- end
53
-
54
- it "should return modified source" do
55
- expect(template.source).to eq("<%= raw(text) %>")
56
- end
57
-
58
- it "should change updated_at", :supports_updated_at do
59
- expect(template.updated_at).to be > updated_at
60
- end
61
- end
62
-
63
- describe "#method_name" do
64
- before do
65
- ActionView::Template.define_method(
66
- :method_name_without_deface,
67
- ActionView::Template.instance_method(:method_name)
68
- )
69
- end
70
-
71
- it "returns hash of overrides plus original method_name " do
72
- deface_hash = Deface::Override.digest(virtual_path: 'posts/index')
73
- super_method = template.method(:method_name).super_method
74
- method_name = "_#{Digest::MD5.new.update("#{deface_hash}_#{super_method.call}").hexdigest}"
75
-
76
- expect(template.send(:method_name)).to eq(method_name)
77
- end
78
- end
79
-
80
- describe "non erb or haml template" do
49
+ describe "unsupported template" do
81
50
  let(:source) { "xml.post => :blah" }
82
51
  let(:path) { "/some/path/to/file.erb" }
83
52
  let(:handler) { ActionView::Template::Handlers::Builder }
@@ -130,17 +99,55 @@ describe Deface::ActionViewExtensions do
130
99
  locals: local_assigns.keys
131
100
  } }
132
101
 
133
- let!(:deface) {
102
+ it 'renders the template modified by deface using :replace' do
134
103
  Deface::Override.new(
135
104
  virtual_path: virtual_path,
136
105
  name: "Posts#index",
137
106
  replace: "p",
138
107
  text: "<h1>Argh!</h1>"
139
108
  )
140
- }
141
109
 
142
- it 'renders the template modified by deface' do
143
110
  expect(template.render(view, local_assigns)).to eq(%{"<h1>Argh!</h1>some <br> text"})
144
111
  end
112
+
113
+ it 'renders the template modified by deface using :remove' do
114
+ Deface::Override.new(
115
+ virtual_path: virtual_path,
116
+ name: "Posts#index",
117
+ remove: "p",
118
+ )
119
+
120
+ expect(template.render(view, local_assigns)).to eq(%{"some <br> text"})
121
+ end
122
+
123
+ context 'with a haml template' do
124
+ let(:source) { "%p test\n= raw(text)\n" }
125
+ let(:handler) { Haml::Plugin }
126
+
127
+ it 'renders the template modified by deface using :remove' do
128
+ Deface::Override.new(
129
+ virtual_path: virtual_path,
130
+ name: "Posts#index",
131
+ remove: "p",
132
+ )
133
+
134
+ expect(template.render(view, local_assigns)).to eq(%{\nsome <br> text})
135
+ end
136
+ end
137
+
138
+ context 'with a slim template' do
139
+ let(:source) { "p test\n= raw(text)\n" }
140
+ let(:handler) { Slim::RailsTemplate.new }
141
+
142
+ it 'renders the template modified by deface using :remove' do
143
+ Deface::Override.new(
144
+ virtual_path: virtual_path,
145
+ name: "Posts#index",
146
+ remove: "p",
147
+ )
148
+
149
+ expect(template.render(view, local_assigns)).to eq(%{\nsome <br> text\n})
150
+ end
151
+ end
145
152
  end
146
153
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deface
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian D Quinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -148,14 +162,14 @@ dependencies:
148
162
  requirements:
149
163
  - - "~>"
150
164
  - !ruby/object:Gem::Version
151
- version: '3.0'
165
+ version: '4.1'
152
166
  type: :development
153
167
  prerelease: false
154
168
  version_requirements: !ruby/object:Gem::Requirement
155
169
  requirements:
156
170
  - - "~>"
157
171
  - !ruby/object:Gem::Version
158
- version: '3.0'
172
+ version: '4.1'
159
173
  - !ruby/object:Gem::Dependency
160
174
  name: simplecov
161
175
  requirement: !ruby/object:Gem::Requirement
@@ -206,11 +220,13 @@ extensions: []
206
220
  extra_rdoc_files:
207
221
  - README.markdown
208
222
  files:
223
+ - ".github/dependabot.yml"
224
+ - ".github/workflows/main.yml"
209
225
  - ".gitignore"
210
226
  - ".rspec"
211
- - ".travis.yml"
212
227
  - Appraisals
213
228
  - CHANGELOG.markdown
229
+ - CONTRIBUTING.md
214
230
  - Gemfile
215
231
  - MIT-LICENSE
216
232
  - README.markdown
@@ -220,9 +236,11 @@ files:
220
236
  - bin/rails-sandbox
221
237
  - bin/sandbox
222
238
  - bin/sandbox-setup
239
+ - bin/setup
223
240
  - deface.gemspec
224
241
  - gemfiles/rails_5.2.gemfile
225
242
  - gemfiles/rails_6.0.gemfile
243
+ - gemfiles/rails_6.1.gemfile
226
244
  - gemfiles/rails_6_1.gemfile
227
245
  - lib/deface.rb
228
246
  - lib/deface/action_view_extensions.rb
@@ -340,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
358
  - !ruby/object:Gem::Version
341
359
  version: '0'
342
360
  requirements: []
343
- rubygems_version: 3.2.3
361
+ rubygems_version: 3.2.32
344
362
  signing_key:
345
363
  specification_version: 4
346
364
  summary: Deface is a library that allows you to customize ERB, Haml and Slim views
data/.travis.yml DELETED
@@ -1,26 +0,0 @@
1
- script: "bundle exec rake"
2
-
3
- cache:
4
- bundler: true
5
-
6
- rvm:
7
- - 2.5.8
8
- - 2.6.6
9
- - 2.7.2
10
- - 3.0.0
11
-
12
- gemfile:
13
- - gemfiles/rails_5.2.gemfile
14
- - gemfiles/rails_6.0.gemfile
15
- - gemfiles/rails_6_1.gemfile
16
-
17
- matrix:
18
- exclude:
19
- - rvm: 2.6.6
20
- gemfile: gemfiles/rails_5.2.gemfile
21
- - rvm: 2.7.2
22
- gemfile: gemfiles/rails_5.2.gemfile
23
- - rvm: 3.0.0
24
- gemfile: gemfiles/rails_5.2.gemfile
25
- - rvm: 3.0.0
26
- gemfile: gemfiles/rails_6.0.gemfile