deface 0.7.1 → 0.7.2
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/.travis.yml +6 -0
- data/README.markdown +8 -0
- data/deface.gemspec +1 -1
- data/lib/deface/override.rb +4 -2
- data/lib/deface/parser.rb +15 -0
- data/lib/deface/railtie.rb +1 -1
- data/spec/deface/override_spec.rb +15 -0
- data/spec/deface/parser_spec.rb +25 -2
- metadata +5 -4
data/.travis.yml
ADDED
data/README.markdown
CHANGED
@@ -99,6 +99,14 @@ Replaces all instances of `h1` in the `posts/_form.html.erb` partial with `<h1>N
|
|
99
99
|
:replace => "h1",
|
100
100
|
:text => "<h1>New Post</h1>")
|
101
101
|
|
102
|
+
Alternatively pass it a block of code to run:
|
103
|
+
|
104
|
+
Deface::Override.new(:virtual_path => "posts/_form",
|
105
|
+
:name => "example-1",
|
106
|
+
:replace => "h1") do
|
107
|
+
"<h1>New Post</h1>"
|
108
|
+
end
|
109
|
+
|
102
110
|
Inserts `<%= link_to "List Comments", comments_url(post) %>` before all instances of `p` with css class `comment` in `posts/index.html.erb`
|
103
111
|
|
104
112
|
Deface::Override.new(:virtual_path => "posts/index",
|
data/deface.gemspec
CHANGED
data/lib/deface/override.rb
CHANGED
@@ -60,7 +60,7 @@ module Deface
|
|
60
60
|
# :sequence => {:after => "override_name") - the current override will be applied after the named override passed.
|
61
61
|
# * <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
|
62
62
|
#
|
63
|
-
def initialize(args)
|
63
|
+
def initialize(args, &content)
|
64
64
|
unless Rails.application.try(:config).respond_to?(:deface) and Rails.application.try(:config).deface.try(:overrides)
|
65
65
|
@@_early << args
|
66
66
|
warn "[WARNING] Deface railtie has not initialized yet, override '#{args[:name]}' is being declared too early."
|
@@ -70,6 +70,8 @@ module Deface
|
|
70
70
|
raise(ArgumentError, ":name must be defined") unless args.key? :name
|
71
71
|
raise(ArgumentError, ":virtual_path must be defined") if args[:virtual_path].blank?
|
72
72
|
|
73
|
+
args[:text] = content.call if block_given?
|
74
|
+
|
73
75
|
virtual_key = args[:virtual_path].to_sym
|
74
76
|
name_key = args[:name].to_s.parameterize
|
75
77
|
|
@@ -336,7 +338,7 @@ module Deface
|
|
336
338
|
virtual_path = details[:virtual_path]
|
337
339
|
return [] if virtual_path.nil?
|
338
340
|
|
339
|
-
virtual_path = virtual_path
|
341
|
+
virtual_path = virtual_path.gsub(/^\//, '')
|
340
342
|
|
341
343
|
result = []
|
342
344
|
result << self.all[virtual_path.to_sym].try(:values)
|
data/lib/deface/parser.rb
CHANGED
@@ -74,6 +74,21 @@ module Deface
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.convert(source)
|
77
|
+
if source.encoding_aware?
|
78
|
+
# Look for # encoding: *. If we find one, we'll encode the
|
79
|
+
# String in that encoding, otherwise, we'll use the
|
80
|
+
# default external encoding.
|
81
|
+
encoding = source.scan(/#{ActionView::Template::Handlers::ERB.const_get(:ENCODING_TAG)}/).first.try(:last) || Encoding.default_external
|
82
|
+
|
83
|
+
# Tag the source with the default external encoding
|
84
|
+
# or the encoding specified in the file
|
85
|
+
source.force_encoding(encoding)
|
86
|
+
|
87
|
+
unless source.valid_encoding?
|
88
|
+
raise ActionView::WrongEncodingError.new(source, encoding)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
77
92
|
erb_markup!(source)
|
78
93
|
|
79
94
|
if source =~ /<html.*?(?:(?!>)[\s\S])*>/
|
data/lib/deface/railtie.rb
CHANGED
@@ -16,7 +16,7 @@ module Deface
|
|
16
16
|
|
17
17
|
config.to_prepare &method(:activate).to_proc
|
18
18
|
|
19
|
-
# configures basic deface environment,
|
19
|
+
# configures basic deface environment, which gets replaced
|
20
20
|
# with real environment if deface is not disabled
|
21
21
|
#
|
22
22
|
initializer "deface.add_configuration", :before => :load_environment_config do |app|
|
@@ -118,6 +118,21 @@ module Deface
|
|
118
118
|
|
119
119
|
end
|
120
120
|
|
121
|
+
describe "with block" do
|
122
|
+
before(:each) do
|
123
|
+
#stub view paths to be local spec/assets directory
|
124
|
+
ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
|
125
|
+
|
126
|
+
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1") do
|
127
|
+
"This is replacement text for the h1"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should set source to block content" do
|
132
|
+
@override.source.should == "This is replacement text for the h1"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
121
136
|
describe "#source_element" do
|
122
137
|
before(:each) do
|
123
138
|
@override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<%= method :opt => 'x' & 'y' %>")
|
data/spec/deface/parser_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Deface
|
@@ -19,7 +21,7 @@ module Deface
|
|
19
21
|
if RUBY_VERSION < "1.9"
|
20
22
|
parsed.should == "<html>\n<head><title>Hello</title></head>\n<body>test</body>\n</html>".split("\n")
|
21
23
|
else
|
22
|
-
parsed.should == "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=
|
24
|
+
parsed.should == "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Hello</title>\n</head>\n<body>test</body>\n</html>".split("\n")
|
23
25
|
end
|
24
26
|
|
25
27
|
parsed = Deface::Parser.convert("<html><title>test</title></html>")
|
@@ -28,7 +30,7 @@ module Deface
|
|
28
30
|
if RUBY_VERSION < "1.9"
|
29
31
|
parsed.should == ["<html><head><title>test</title></head></html>"]
|
30
32
|
else
|
31
|
-
parsed.should == "<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=
|
33
|
+
parsed.should == "<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>test</title>\n</head></html>".split("\n")
|
32
34
|
end
|
33
35
|
|
34
36
|
parsed = Deface::Parser.convert("<html><p>test</p></html>")
|
@@ -84,6 +86,27 @@ module Deface
|
|
84
86
|
it "should escape contents code tags" do
|
85
87
|
Deface::Parser.convert("<% method_name(:key => 'value') %>").to_s.should == "<code erb-silent> method_name(:key => 'value') </code>"
|
86
88
|
end
|
89
|
+
|
90
|
+
if "".encoding_aware?
|
91
|
+
it "should respect valid encoding tag" do
|
92
|
+
source = %q{<%# encoding: ISO-8859-1 %>Can you say ümlaut?}
|
93
|
+
Deface::Parser.convert(source)
|
94
|
+
source.encoding.name.should == 'ISO-8859-1'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should force default encoding" do
|
98
|
+
source = %q{Can you say ümlaut?}
|
99
|
+
source.force_encoding('ISO-8859-1')
|
100
|
+
Deface::Parser.convert(source)
|
101
|
+
source.encoding.should == Encoding.default_external
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should force default encoding" do
|
105
|
+
source = %q{<%# encoding: US-ASCII %>Can you say ümlaut?}
|
106
|
+
lambda { Deface::Parser.convert(source) }.should raise_error(ActionView::WrongEncodingError)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
87
110
|
end
|
88
111
|
|
89
112
|
describe "#undo_erb_markup" 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: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
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-
|
18
|
+
date: 2011-11-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -75,6 +75,7 @@ extra_rdoc_files:
|
|
75
75
|
- README.markdown
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
|
+
- .travis.yml
|
78
79
|
- Gemfile
|
79
80
|
- MIT-LICENSE
|
80
81
|
- README.markdown
|