deface 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/README.markdown +2 -2
- data/deface.gemspec +1 -1
- data/lib/deface/action_view_extensions.rb +24 -2
- data/lib/deface/override.rb +15 -8
- data/spec/deface/haml_converter_spec.rb +6 -6
- data/spec/deface/override_spec.rb +55 -19
- data/spec/spec_helper.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44620268997d5e65befca4180c45dc73b0ecf46d5fbbd1fc38862c595d6e3f23
|
4
|
+
data.tar.gz: 1a79c921115393d0907578ac97798e14de5fa65ac440e540c8c70723f1c0bbba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50113476bc070b1392cf90839ea872f59e423cf0945b4d983b1e83c7b2cbe4336e0480dbe97028f8e3eeb3994409690fb3fb842d28c015dc513a716cc84ae091
|
7
|
+
data.tar.gz: a2ea2e19e0d31745e9e27ff981ac46e723692f61267f570636a1fa692f9ac610599a96f33d237bd8edbf77d3b8f61809f62abe84123886b91279e5cf07a92e4e
|
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<p style="float:right;">
|
2
2
|
<a href="http://secure.travis-ci.org/spree/deface">
|
3
|
-
<img src="https://secure.travis-ci.org/spree/deface.
|
3
|
+
<img src="https://secure.travis-ci.org/spree/deface.svg?branch=master">
|
4
4
|
</a>
|
5
5
|
</p>
|
6
6
|
|
@@ -116,7 +116,7 @@ You should save your overrides in the ````app/overrides````, normally one overri
|
|
116
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
117
|
* <tt>:sequence => n</tt> - where n is a positive or negative integer (lower numbers get applied first, default 100).
|
118
118
|
* <tt>:sequence => {:before => "*override_name*"}</tt> - where "*override_name*" is the name of an override defined for the
|
119
|
-
same
|
119
|
+
same virtual_path, the current override will be appplied before
|
120
120
|
the named override passed.
|
121
121
|
* <tt>:sequence => {:after => "*override_name*"}</tt> - the current override will be applied after the named override passed.
|
122
122
|
|
data/deface.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "deface"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.5.0"
|
4
4
|
|
5
5
|
s.authors = ["Brian D Quinn"]
|
6
6
|
s.description = "Deface is a library that allows you to customize ERB, Haml and Slim views in a Rails application without editing the underlying view."
|
@@ -28,8 +28,10 @@ ActionView::Template.class_eval do
|
|
28
28
|
#
|
29
29
|
def render(view, locals, buffer=nil, &block)
|
30
30
|
|
31
|
-
if view.is_a?(ActionView::
|
32
|
-
mod = ActionView::
|
31
|
+
if Rails.version < "6.0.0.beta1" && view.is_a?(ActionView::CompiledTemplates)
|
32
|
+
mod = ActionView::CompiledTemplates
|
33
|
+
elsif Rails.version >= "6.0.0.beta1" && view.is_a?(ActionDispatch::DebugView)
|
34
|
+
mod = ActionDispatch::DebugView
|
33
35
|
else
|
34
36
|
mod = view.singleton_class
|
35
37
|
end
|
@@ -74,6 +76,26 @@ ActionView::Template.class_eval do
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
79
|
+
# Rails 6 fix
|
80
|
+
# https://github.com/rails/rails/commit/ec5c946138f63dc975341d6521587adc74f6b441
|
81
|
+
# https://github.com/rails/rails/commit/ccfa01c36e79013881ffdb7ebe397cec733d15b2#diff-dfb6e0314ad9639bab460ea64871aa47R27
|
82
|
+
if defined?( ActionView::Template::Handlers::ERB::Erubi)
|
83
|
+
ActionView::Template::Handlers::ERB::Erubi.class_eval do
|
84
|
+
def initialize(input, properties = {})
|
85
|
+
@newline_pending = 0
|
86
|
+
|
87
|
+
# Dup properties so that we don't modify argument
|
88
|
+
properties = Hash[properties]
|
89
|
+
properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
|
90
|
+
properties[:postamble] = "@output_buffer.to_s"
|
91
|
+
properties[:bufvar] = "@output_buffer"
|
92
|
+
properties[:escapefunc] = ""
|
93
|
+
|
94
|
+
super
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
77
99
|
#fix for Rails 3.1 not setting virutal_path anymore (BOO!)
|
78
100
|
if defined?(ActionView::Resolver::Path)
|
79
101
|
ActionView::Resolver::Path.class_eval { alias_method :virtual, :to_s }
|
data/lib/deface/override.rb
CHANGED
@@ -214,16 +214,23 @@ module Deface
|
|
214
214
|
# check if method is compiled for the current virtual path
|
215
215
|
#
|
216
216
|
def expire_compiled_template
|
217
|
-
if
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
217
|
+
if Rails.version < "6.0.0.beta1"
|
218
|
+
if compiled_method_name = ActionView::CompiledTemplates.instance_methods.detect { |name| name =~ /#{args[:virtual_path].gsub(/[^a-z_]/, '_')}/ }
|
219
|
+
#if the compiled method does not contain the current deface digest
|
220
|
+
#then remove the old method - this will allow the template to be
|
221
|
+
#recompiled the next time it is rendered (showing the latest changes)
|
222
|
+
|
223
|
+
unless compiled_method_name =~ /\A_#{self.class.digest(:virtual_path => @args[:virtual_path])}_/
|
224
|
+
ActionView::CompiledTemplates.send :remove_method, compiled_method_name
|
225
|
+
end
|
226
|
+
end
|
227
|
+
else
|
228
|
+
if compiled_method_name = ActionDispatch::DebugView.instance_methods.detect { |name| name =~ /#{args[:virtual_path].gsub(/[^a-z_]/, '_')}/ }
|
229
|
+
unless compiled_method_name =~ /\A_#{self.class.digest(:virtual_path => @args[:virtual_path])}_/
|
230
|
+
ActionDispatch::DebugView.send :remove_method, compiled_method_name
|
231
|
+
end
|
224
232
|
end
|
225
233
|
end
|
226
|
-
|
227
234
|
end
|
228
235
|
|
229
236
|
end
|
@@ -24,18 +24,18 @@ module Deface
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should handle simple haml attributes" do
|
27
|
-
expect(haml_to_erb("%meta{:charset => 'utf-8'}")).to eq("<meta charset='utf-8'
|
27
|
+
expect(haml_to_erb("%meta{:charset => 'utf-8'}")).to eq("<meta charset='utf-8' />")
|
28
28
|
expect(haml_to_erb("%p(alt='hello world')Hello World!")).to eq("<p alt='hello world'>Hello World!</p>")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should handle haml attributes with commas" do
|
32
|
-
expect(haml_to_erb("%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'
|
33
|
-
expect(haml_to_erb("%meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'
|
34
|
-
expect(haml_to_erb('%meta{:name => "author", :content => "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author'
|
35
|
-
expect(haml_to_erb('%meta(name="author" content="Example, Inc.")')).to eq("<meta content='Example, Inc.' name='author'
|
32
|
+
expect(haml_to_erb("%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />")
|
33
|
+
expect(haml_to_erb("%meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />")
|
34
|
+
expect(haml_to_erb('%meta{:name => "author", :content => "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author' />")
|
35
|
+
expect(haml_to_erb('%meta(name="author" content="Example, Inc.")')).to eq("<meta content='Example, Inc.' name='author' />")
|
36
36
|
|
37
37
|
if RUBY_VERSION > "1.9"
|
38
|
-
expect(haml_to_erb('%meta{name: "author", content: "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author'
|
38
|
+
expect(haml_to_erb('%meta{name: "author", content: "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author' />")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -561,37 +561,73 @@ module Deface
|
|
561
561
|
|
562
562
|
describe "#expire_compiled_template" do
|
563
563
|
it "should remove compiled method when method name matches virtual path but not digest" do
|
564
|
-
|
564
|
+
if Rails.version < "6.0.0.beta1"
|
565
|
+
instance_methods_count = ActionView::CompiledTemplates.instance_methods.size
|
565
566
|
|
566
|
-
|
567
|
-
|
568
|
-
|
567
|
+
module ActionView::CompiledTemplates
|
568
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
569
|
+
true #not a real method
|
570
|
+
end
|
571
|
+
|
572
|
+
def _f34556de606cec51d4f6791163fab456_posts_edit_123123123
|
573
|
+
true #not a real method
|
574
|
+
end
|
569
575
|
end
|
570
576
|
|
571
|
-
|
572
|
-
|
577
|
+
expect(ActionView::CompiledTemplates.instance_methods.size).to eq(instance_methods_count + 2)
|
578
|
+
@override.send(:expire_compiled_template)
|
579
|
+
expect(ActionView::CompiledTemplates.instance_methods.size).to eq(instance_methods_count + 1)
|
580
|
+
|
581
|
+
else
|
582
|
+
instance_methods_count = ActionDispatch::DebugView.instance_methods.size
|
583
|
+
|
584
|
+
class ActionDispatch::DebugView
|
585
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
586
|
+
true #not a real method
|
587
|
+
end
|
588
|
+
|
589
|
+
def _f34556de606cec51d4f6791163fab456_posts_edit_123123123
|
590
|
+
true #not a real method
|
591
|
+
end
|
573
592
|
end
|
574
|
-
end
|
575
593
|
|
576
|
-
|
577
|
-
|
578
|
-
|
594
|
+
expect(ActionDispatch::DebugView.instance_methods.size).to eq(instance_methods_count + 2)
|
595
|
+
@override.send(:expire_compiled_template)
|
596
|
+
expect(ActionDispatch::DebugView.instance_methods.size).to eq(instance_methods_count + 1)
|
597
|
+
end
|
579
598
|
end
|
580
599
|
|
581
600
|
it "should not remove compiled method when virtual path and digest matach" do
|
582
|
-
|
601
|
+
if Rails.version < "6.0.0.beta1"
|
602
|
+
instance_methods_count = ActionView::CompiledTemplates.instance_methods.size
|
583
603
|
|
584
|
-
|
585
|
-
|
586
|
-
|
604
|
+
module ActionView::CompiledTemplates
|
605
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
606
|
+
true #not a real method
|
607
|
+
end
|
587
608
|
end
|
588
|
-
end
|
589
609
|
|
590
|
-
|
610
|
+
expect(Deface::Override).to receive(:digest).and_return('e235fa404c3c2281d4f6791162b1c638')
|
591
611
|
|
592
|
-
|
593
|
-
|
594
|
-
|
612
|
+
expect(ActionView::CompiledTemplates.instance_methods.size).to eq(instance_methods_count + 1)
|
613
|
+
@override.send(:expire_compiled_template)
|
614
|
+
expect(ActionView::CompiledTemplates.instance_methods.size).to eq(instance_methods_count + 1)
|
615
|
+
|
616
|
+
else
|
617
|
+
instance_methods_count = ActionDispatch::DebugView.instance_methods.size
|
618
|
+
|
619
|
+
class ActionDispatch::DebugView
|
620
|
+
def _e235fa404c3c2281d4f6791162b1c638_posts_index_123123123
|
621
|
+
true #not a real method
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
expect(Deface::Override).to receive(:digest).and_return('e235fa404c3c2281d4f6791162b1c638')
|
626
|
+
|
627
|
+
expect(ActionDispatch::DebugView.instance_methods.size).to eq(instance_methods_count + 1)
|
628
|
+
@override.send(:expire_compiled_template)
|
629
|
+
expect(ActionDispatch::DebugView.instance_methods.size).to eq(instance_methods_count + 1)
|
630
|
+
end
|
595
631
|
end
|
596
632
|
end
|
597
633
|
|
data/spec/spec_helper.rb
CHANGED
@@ -42,6 +42,16 @@ RSpec.configure do |config|
|
|
42
42
|
config.mock_framework = :rspec
|
43
43
|
end
|
44
44
|
|
45
|
+
if Rails.version < "6.0.0.beta1"
|
46
|
+
module ActionView::CompiledTemplates
|
47
|
+
#empty module for testing purposes
|
48
|
+
end
|
49
|
+
else
|
50
|
+
class ActionDispatch::DebugView
|
51
|
+
#empty module for testing purposes
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
45
55
|
shared_context "mock Rails" do
|
46
56
|
before(:each) do
|
47
57
|
rails_version = Rails::VERSION::STRING
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian D Quinn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|