deface 0.5.6 → 0.5.7
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 +1 -3
- data/deface.gemspec +9 -28
- data/lib/deface/override.rb +7 -2
- data/lib/deface/parser.rb +3 -1
- data/lib/deface/template_helper.rb +8 -2
- data/spec/deface/parser_spec.rb +6 -0
- data/spec/deface/template_helper_spec.rb +39 -10
- metadata +7 -7
data/README.markdown
CHANGED
@@ -126,6 +126,4 @@ Deface uses the amazing Nokogiri library (and in turn libxml) for parsing HTML /
|
|
126
126
|
|
127
127
|
2. Parsing will fail and result in invalid output if ERB blocks are responsible for closing an HTML tag that was opened normally, i.e. don't do this:
|
128
128
|
|
129
|
-
|
130
|
-
<div <%= ">" %>
|
131
|
-
|
129
|
+
<div <%= ">" %>
|
data/deface.gemspec
CHANGED
@@ -1,39 +1,20 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
1
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.5.
|
2
|
+
s.name = "deface"
|
3
|
+
s.version = "0.5.7"
|
9
4
|
|
10
|
-
s.authors = ["Brian Quinn"]
|
11
|
-
s.description =
|
12
|
-
s.email =
|
5
|
+
s.authors = ["Brian D Quinn"]
|
6
|
+
s.description = "Deface is a library that allows you to customize ERB views in a Rails application without editing the underlying view."
|
7
|
+
s.email = "brian@railsdog.com"
|
13
8
|
s.extra_rdoc_files = [
|
14
9
|
"README.markdown"
|
15
10
|
]
|
16
11
|
s.files = `git ls-files`.split("\n")
|
17
12
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.homepage =
|
13
|
+
s.homepage = "http://github.com/railsdog/deface"
|
19
14
|
s.rdoc_options = ["--charset=UTF-8"]
|
20
15
|
s.require_paths = ["lib"]
|
21
|
-
s.summary =
|
22
|
-
|
23
|
-
if s.respond_to? :specification_version then
|
24
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
-
s.specification_version = 3
|
16
|
+
s.summary = "Deface is a library that allows you to customize ERB views in Rails"
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
30
|
-
else
|
31
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
|
32
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
33
|
-
end
|
34
|
-
else
|
35
|
-
s.add_dependency(%q<nokogiri>, ["~> 1.4.3"])
|
36
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
37
|
-
end
|
18
|
+
s.add_dependency('nokogiri', '~> 1.5.0')
|
19
|
+
s.add_dependency('rails', '>= 3.0.0')
|
38
20
|
end
|
39
|
-
|
data/lib/deface/override.rb
CHANGED
@@ -154,9 +154,14 @@ module Deface
|
|
154
154
|
|
155
155
|
# applies all applicable overrides to given source
|
156
156
|
#
|
157
|
-
def self.apply(source, details)
|
157
|
+
def self.apply(source, details, log=true)
|
158
158
|
overrides = find(details)
|
159
|
-
|
159
|
+
|
160
|
+
if log
|
161
|
+
@enable_logging ||= defined?(Rails)
|
162
|
+
else
|
163
|
+
@enable_logging = false
|
164
|
+
end
|
160
165
|
|
161
166
|
if @enable_logging && overrides.size > 0
|
162
167
|
Rails.logger.info "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for '#{details[:virtual_path]}'"
|
data/lib/deface/parser.rb
CHANGED
@@ -76,8 +76,10 @@ module Deface
|
|
76
76
|
def self.convert(source)
|
77
77
|
erb_markup!(source)
|
78
78
|
|
79
|
-
if source =~
|
79
|
+
if source =~ /<html.*?(?:(?!>)[\s\S])*>/
|
80
80
|
Nokogiri::HTML::Document.parse(source)
|
81
|
+
elsif source =~ /<body.*?(?:(?!>)[\s\S])*>/
|
82
|
+
Nokogiri::HTML::Document.parse(source).css('body').first
|
81
83
|
else
|
82
84
|
Nokogiri::HTML::DocumentFragment.parse(source)
|
83
85
|
end
|
@@ -2,7 +2,7 @@ module Deface
|
|
2
2
|
module TemplateHelper
|
3
3
|
|
4
4
|
# used to find source for a partial or template using virutal_path
|
5
|
-
def load_template_source(virtual_path, partial)
|
5
|
+
def load_template_source(virtual_path, partial, include_overrides=true)
|
6
6
|
parts = virtual_path.split("/")
|
7
7
|
prefix = []
|
8
8
|
if parts.size == 2
|
@@ -15,7 +15,13 @@ module Deface
|
|
15
15
|
|
16
16
|
@lookup_context ||= ActionView::LookupContext.new(ActionController::Base.view_paths, {:formats => [:html]})
|
17
17
|
|
18
|
-
@lookup_context.find(name, prefix, partial).source
|
18
|
+
source = @lookup_context.find(name, prefix, partial).source
|
19
|
+
|
20
|
+
if include_overrides
|
21
|
+
Deface::Override.apply(source, {:virtual_path => virtual_path}, false)
|
22
|
+
else
|
23
|
+
source
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
#gets source erb for an element
|
data/spec/deface/parser_spec.rb
CHANGED
@@ -29,6 +29,12 @@ module Deface
|
|
29
29
|
parsed.should == "<html><body><p>test</p></body></html>".split("\n") #ignore doctype added by noko
|
30
30
|
end
|
31
31
|
|
32
|
+
it "should parse body tag" do
|
33
|
+
parsed = Deface::Parser.convert("<body id=\"body\" <%= something %>>test</body>")
|
34
|
+
parsed.should be_an_instance_of(Nokogiri::XML::Element)
|
35
|
+
parsed.to_s.should == "<body id=\"body\" data-erb-0=\"<%= something %>\">test</body>"
|
36
|
+
end
|
37
|
+
|
32
38
|
it "should convert <% ... %>" do
|
33
39
|
Deface::Parser.convert("<% method_name %>").to_s.should == "<code erb-silent> method_name </code>"
|
34
40
|
end
|
@@ -10,20 +10,49 @@ module Deface
|
|
10
10
|
ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
describe "with no overrides defined" do
|
14
|
+
it "should return source for partial" do
|
15
|
+
load_template_source("shared/_post", false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
it "should return source for template" do
|
19
|
+
load_template_source("shared/person", false).should == "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return source for namespaced template" do
|
23
|
+
load_template_source("admin/posts/index", false).should == "<h1>Manage Posts</h1>\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise exception for non-existing file" do
|
27
|
+
lambda { load_template_source("tester/_post", false) }.should raise_error(ActionView::MissingTemplate)
|
28
|
+
end
|
20
29
|
|
21
|
-
it "should return source for namespaced template" do
|
22
|
-
load_template_source("admin/posts/index", false).should == "<h1>Manage Posts</h1>\n"
|
23
30
|
end
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
describe "with overrides defined" do
|
33
|
+
before(:all) do
|
34
|
+
Deface::Override.all.clear
|
35
|
+
Deface::Override.new(:virtual_path => "shared/_post", :name => "shared#post", :remove => "p")
|
36
|
+
Deface::Override.new(:virtual_path => "shared/person", :name => "shared#person", :replace => "p", :text => "<h1>Argh!</h1>")
|
37
|
+
Deface::Override.new(:virtual_path => "admin/posts/index", :name => "admin#posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return source for partial including overrides" do
|
41
|
+
load_template_source("shared/_post", false).should == "\n<%= \"And I've got ERB\" %>"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return source for partial excluding overrides" do
|
45
|
+
load_template_source("shared/_post", false, false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return source for template including overrides" do
|
49
|
+
load_template_source("shared/person", false).should == "<h1>Argh!</h1>\n<%= \"I've got ERB too\" %>"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return source for namespaced template including overrides" do
|
53
|
+
load_template_source("admin/posts/index", false).should == "<h1>Argh!</h1>"
|
54
|
+
end
|
55
|
+
|
27
56
|
end
|
28
57
|
|
29
58
|
end
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 5
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 7
|
10
|
+
version: 0.5.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
- Brian Quinn
|
13
|
+
- Brian D Quinn
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements: []
|
111
111
|
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.6.2
|
114
114
|
signing_key:
|
115
115
|
specification_version: 3
|
116
116
|
summary: Deface is a library that allows you to customize ERB views in Rails
|