deface 1.2.0 → 1.3.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/deface.gemspec +2 -2
- data/lib/deface/haml_converter.rb +1 -2
- data/lib/deface/override.rb +10 -0
- data/lib/deface/railtie.rb +2 -2
- data/spec/deface/haml_converter_spec.rb +9 -9
- data/spec/deface/override_spec.rb +17 -1
- data/spec/deface/template_helper_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf234b6836f2b2d5bee1e3ae0d73632c048c0fa5
|
4
|
+
data.tar.gz: 1cdc7e44036fb3bf0fc9b5bcfe6ee485d4b8d6fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 893ca0bc578ad92b43c6758583e37c1a712e63737dc0c7d7a0a06efcbe2c107c100fe52a973d65ce6251378f0774384159e1eccf842036618f5157992b8f93a5
|
7
|
+
data.tar.gz: 1b476d0268efbf0d74b6af40a34b1fc1a6cf1be2f8c72eb58d542adf02706c5d86ddb68551139a80aae3051ce857e9bf042e53d763100b220d79a878af7a4eb8
|
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.3.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."
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency('appraisal')
|
24
24
|
s.add_development_dependency('erubis')
|
25
25
|
s.add_development_dependency('rspec', '>= 3.1.0')
|
26
|
-
s.add_development_dependency('haml', '
|
26
|
+
s.add_development_dependency('haml', ['>= 4.0', '< 6'])
|
27
27
|
s.add_development_dependency('slim', '~> 3.0')
|
28
28
|
s.add_development_dependency('simplecov', '>= 0.6.4')
|
29
29
|
s.add_development_dependency('generator_spec', '~> 0.8')
|
@@ -20,7 +20,7 @@ module Deface
|
|
20
20
|
def parse_old_attributes(line)
|
21
21
|
attributes_hash, rest, last_line = super(line)
|
22
22
|
|
23
|
-
attributes_hash = deface_attributes(attributes_hash)
|
23
|
+
attributes_hash = "{#{deface_attributes(attributes_hash)}}"
|
24
24
|
|
25
25
|
return attributes_hash, rest, last_line
|
26
26
|
end
|
@@ -34,7 +34,6 @@ module Deface
|
|
34
34
|
return attributes, rest, last_line
|
35
35
|
end
|
36
36
|
private
|
37
|
-
|
38
37
|
# coverts { attributes into deface compatibily attributes
|
39
38
|
def deface_attributes(attrs)
|
40
39
|
return if attrs.nil?
|
data/lib/deface/override.rb
CHANGED
@@ -26,6 +26,16 @@ module Deface
|
|
26
26
|
return
|
27
27
|
end
|
28
28
|
|
29
|
+
# If no name was specified, use the filename and line number of the caller
|
30
|
+
# Including the line number ensure unique names if multiple overrides
|
31
|
+
# are defined in the same file
|
32
|
+
unless args.key? :name
|
33
|
+
parts = caller[0].split(':')
|
34
|
+
file_name = File.basename(parts[0], '.rb')
|
35
|
+
line_number = parts[1]
|
36
|
+
args[:name] = "#{file_name}_#{line_number}"
|
37
|
+
end
|
38
|
+
|
29
39
|
raise(ArgumentError, ":name must be defined") unless args.key? :name
|
30
40
|
raise(ArgumentError, ":virtual_path must be defined") if args[:virtual_path].blank?
|
31
41
|
|
data/lib/deface/railtie.rb
CHANGED
@@ -36,7 +36,7 @@ module Deface
|
|
36
36
|
initializer "deface.tweak_eager_loading", :before => :set_load_path do |app|
|
37
37
|
|
38
38
|
# application
|
39
|
-
app.config.eager_load_paths.reject
|
39
|
+
app.config.eager_load_paths = app.config.eager_load_paths.reject { |path| path.to_s =~ /app\/overrides\z/ }
|
40
40
|
|
41
41
|
# railites / engines / extensions
|
42
42
|
railties = if Rails.version >= "4.0"
|
@@ -47,7 +47,7 @@ module Deface
|
|
47
47
|
|
48
48
|
railties.each do |railtie|
|
49
49
|
next unless railtie.respond_to?(:root) && railtie.config.respond_to?(:eager_load_paths)
|
50
|
-
railtie.config.eager_load_paths.reject
|
50
|
+
railtie.config.eager_load_paths = railtie.config.eager_load_paths.reject { |path| path.to_s =~ /app\/overrides\z/ }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -20,22 +20,22 @@ module Deface
|
|
20
20
|
%h2 Welcome to our site!
|
21
21
|
%p= print_information
|
22
22
|
.right.column
|
23
|
-
= render :partial => "sidebar"})).to eq("<div id='content'
|
23
|
+
= render :partial => "sidebar"})).to eq("<div id='content'><div class='left column'><h2>Welcome to our site!</h2><p><%= print_information %></p></div><div class='right column'><%= render :partial => \"sidebar\" %></div></div>")
|
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
|
|
@@ -73,7 +73,7 @@ module Deface
|
|
73
73
|
it "should handle blocks passed to erb loud" do
|
74
74
|
expect(haml_to_erb("= form_for Post.new do |f|
|
75
75
|
%p
|
76
|
-
= f.text_field :name")).to eq("<%= form_for Post.new do |f| %><p
|
76
|
+
= f.text_field :name")).to eq("<%= form_for Post.new do |f| %><p><%= f.text_field :name %></p><% end %>")
|
77
77
|
|
78
78
|
end
|
79
79
|
|
@@ -81,7 +81,7 @@ module Deface
|
|
81
81
|
it "should handle blocks passed to erb silent" do
|
82
82
|
expect(haml_to_erb("- @posts.each do |post|
|
83
83
|
%p
|
84
|
-
= post.name")).to eq("<% @posts.each do |post| %><p
|
84
|
+
= post.name")).to eq("<% @posts.each do |post| %><p><%= post.name %></p><% end %>")
|
85
85
|
|
86
86
|
end
|
87
87
|
end
|
@@ -100,6 +100,22 @@ module Deface
|
|
100
100
|
Deface::Override.new(:virtual_path => "posts/new", :name => "Posts#new", :replace => "h1", :text => "<h1>argh!</h1>")
|
101
101
|
}.to change{Deface::Override.all.size}.by(1)
|
102
102
|
end
|
103
|
+
|
104
|
+
it "should default :name when none is given" do
|
105
|
+
override = Deface::Override.new(:virtual_path => "posts/new", :replace => "h1", :text => "<h1>Derp!</h1>")
|
106
|
+
expect(override.name).not_to be_empty
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should default :name to caller's file name and a line number" do
|
110
|
+
override = Deface::Override.new(:virtual_path => "posts/new", :replace => "h1", :text => "<h1>Derp!</h1>")
|
111
|
+
expect(override.name).to match Regexp.new("#{Regexp.escape(File.basename(__FILE__, '.rb'))}_\\d+")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should use :name argument when given" do
|
115
|
+
name = "Posts#new"
|
116
|
+
override = Deface::Override.new(:virtual_path => "posts/new", :name => name, :replace => "h1", :text => "<h1>Derp!</h1>")
|
117
|
+
expect(override.name).to eq(name)
|
118
|
+
end
|
103
119
|
end
|
104
120
|
|
105
121
|
describe "with :text" do
|
@@ -136,7 +152,7 @@ module Deface
|
|
136
152
|
end
|
137
153
|
|
138
154
|
it "should return erb converted from haml as source" do
|
139
|
-
expect(@override.source).to eq("<strong class='erb' id='message'><%= 'Hello, World!'
|
155
|
+
expect(@override.source).to eq("<strong class='erb' id='message'><%= 'Hello, World!' %></strong>\n")
|
140
156
|
|
141
157
|
expect(@override.source_argument).to eq(:haml)
|
142
158
|
end
|
@@ -17,7 +17,7 @@ module Deface
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return converted source for partial containing haml" do
|
20
|
-
expect(load_template_source("shared/hello", true)).to eq "<div class='<%= @some %>' id='message'><%= 'Hello, World!'
|
20
|
+
expect(load_template_source("shared/hello", true)).to eq "<div class='<%= @some %>' id='message'><%= 'Hello, World!' %></div>\n"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should return converted source for partial containing slim" do
|
data/spec/spec_helper.rb
CHANGED
@@ -78,7 +78,7 @@ shared_context "mock Rails" do
|
|
78
78
|
allow(Time).to receive(:zone).and_return double('zone')
|
79
79
|
allow(Time.zone).to receive(:now).and_return Time.parse('1979-05-25')
|
80
80
|
|
81
|
-
require "haml/template
|
81
|
+
require "haml/template"
|
82
82
|
require 'slim/erb_converter'
|
83
83
|
end
|
84
84
|
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.
|
4
|
+
version: 1.3.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: 2017-
|
11
|
+
date: 2017-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -112,16 +112,22 @@ dependencies:
|
|
112
112
|
name: haml
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '4.0'
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '6'
|
118
121
|
type: :development
|
119
122
|
prerelease: false
|
120
123
|
version_requirements: !ruby/object:Gem::Requirement
|
121
124
|
requirements:
|
122
|
-
- - "
|
125
|
+
- - ">="
|
123
126
|
- !ruby/object:Gem::Version
|
124
127
|
version: '4.0'
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '6'
|
125
131
|
- !ruby/object:Gem::Dependency
|
126
132
|
name: slim
|
127
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -296,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
296
302
|
version: '0'
|
297
303
|
requirements: []
|
298
304
|
rubyforge_project:
|
299
|
-
rubygems_version: 2.6.
|
305
|
+
rubygems_version: 2.6.14
|
300
306
|
signing_key:
|
301
307
|
specification_version: 4
|
302
308
|
summary: Deface is a library that allows you to customize ERB, Haml and Slim views
|