deface 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -12,12 +12,26 @@ Deface is a library that allows you to customize HTML ERB views in a Rails appli
12
12
  It allows you to easily target html & erb elements as the hooks for customization using CSS selectors as supported by Nokogiri.
13
13
 
14
14
  Demo & Testing
15
- ---------------
15
+ --------------
16
16
  You can play with Deface and see its parsing in action at [deface.heroku.com](http://deface.heroku.com)
17
17
 
18
18
 
19
+ Production & Precompiling
20
+ ------------------------
21
+
22
+ 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:
23
+
24
+ bundle exec rake deface:precompile
25
+
26
+ It's important to disable Deface once precompiling is used to prevent overrides getting applied twice. To disable add the following line to your application's `production.rb` file:
27
+
28
+ config.deface.enabled = false
29
+
30
+ NOTE: You can also use precompiling in development mode.
31
+
32
+
19
33
  Deface::Override
20
- =======
34
+ ================
21
35
 
22
36
  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. Note: the source parameter is not required when the "remove" action is specified.
23
37
 
@@ -31,6 +45,12 @@ Action
31
45
 
32
46
  * <tt>:replace</tt> - Replaces all elements that match the supplied selector
33
47
 
48
+ * <tt>:replace_contents</tt> - Replaces the contents of all elements that match the supplied selector
49
+
50
+ * <tt>:surround</tt> - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
51
+
52
+ * <tt>:surround_contents</tt> - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
53
+
34
54
  * <tt>:insert_after</tt> - Inserts after all elements that match the supplied selector
35
55
 
36
56
  * <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
@@ -72,7 +92,7 @@ Optional
72
92
  Examples
73
93
  ========
74
94
 
75
- Replaces all instances of _h1_ in the `posts/_form.html.erb` partial with `<h1>New Post</h1>`
95
+ Replaces all instances of `h1` in the `posts/_form.html.erb` partial with `<h1>New Post</h1>`
76
96
 
77
97
  Deface::Override.new(:virtual_path => "posts/_form",
78
98
  :name => "example-1",
@@ -100,6 +120,13 @@ Removes any ERB block containing the string `helper_method` in the `posts/new.ht
100
120
  :remove => "code[erb-loud]:contains('helper_method')",
101
121
  :original => "<%= helper_method %>")
102
122
 
123
+ 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.
124
+
125
+ Deface::Override.new(:virtual_path => "posts/new",
126
+ :name => "example-5",
127
+ :surround => "div#products",
128
+ :text => "<% if @product.present? %><%= render_original %><% end %>")
129
+
103
130
  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`
104
131
 
105
132
  Deface::Override.new(:virtual_path => 'posts/index',
@@ -111,8 +138,8 @@ Remove an entire ERB if statement (and all it's contents) in the 'admin/products
111
138
 
112
139
  Deface::Override.new(:virtual_path => 'admin/products/index',
113
140
  :name => "remove_if_statement",
114
- :remove => "code[:erb-silent]:contains('if @product.sold?')",
115
- :closing_selector => "code[:erb-silent]:contains('end')"
141
+ :remove => "code[erb-silent]:contains('if @product.sold?')",
142
+ :closing_selector => "code[erb-silent]:contains('end')"
116
143
 
117
144
  Scope
118
145
  =====
@@ -140,12 +167,16 @@ Deface includes a couple of rake tasks that can be helpful when defining or debu
140
167
 
141
168
  rake deface:get_result['admin/products/index']
142
169
 
143
- **deface:test_selector** - Applies a given CSS selector against a parital 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:
170
+ **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:
144
171
 
145
172
  rake deface:test_selector[shared/_head,title]
146
173
 
147
174
  rake deface:test_selector['admin/products/index','div.toolbar']
148
175
 
176
+ **deface:precompile** - Generates compiled views that contain all overrides applied. See `Production & Precompiling` section above for more.
177
+
178
+ rake deface:precompile
179
+
149
180
 
150
181
  Implementation
151
182
  ==============
data/deface.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "deface"
3
- s.version = "0.7.0"
3
+ s.version = "0.7.1"
4
4
 
5
5
  s.authors = ["Brian D Quinn"]
6
6
  s.description = "Deface is a library that allows you to customize ERB views in a Rails application without editing the underlying view."
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency('nokogiri', '~> 1.5.0')
19
19
  s.add_dependency('rails', '>= 3.0.9')
20
20
 
21
- s.add_development_dependency('rspec', '>= 2.6.0')
21
+ s.add_development_dependency('rspec', '>= 2.7.0')
22
22
  end
@@ -2,7 +2,9 @@ ActionView::Template.class_eval do
2
2
  alias_method :rails_initialize, :initialize
3
3
 
4
4
  def initialize(source, identifier, handler, details)
5
- source = Deface::Override.apply(source, details)
5
+ if Rails.application.config.deface.enabled
6
+ source = Deface::Override.apply(source, details)
7
+ end
6
8
 
7
9
  rails_initialize(source, identifier, handler, details)
8
10
  end
@@ -1,9 +1,10 @@
1
1
  module Deface
2
2
 
3
3
  class Environment
4
- attr_accessor :overrides
4
+ attr_accessor :overrides, :enabled
5
5
  def initialize
6
6
  @overrides = Overrides.new
7
+ @enabled = true
7
8
  end
8
9
  end
9
10
 
@@ -18,12 +19,40 @@ module Deface
18
19
  Deface::Override.find(*args)
19
20
  end
20
21
 
21
- def early_check
22
- Deface::Override._early.each do |args|
23
- Deface::Override.new(args)
22
+ def load_all(app)
23
+ # check application for specified overrides paths
24
+ #
25
+ #
26
+ override_paths = app.paths["app/overrides"]
27
+ enumerate_and_load(override_paths, app.root)
28
+
29
+ # check all railties / engines / extensions for overrides
30
+ app.railties.all.each do |railtie|
31
+ next unless railtie.respond_to? :root
32
+
33
+ override_paths = railtie.respond_to?(:paths) ? railtie.paths["app/overrides"] : nil
34
+ enumerate_and_load(override_paths, railtie.root)
35
+ end
36
+ end
37
+
38
+ def early_check
39
+ Deface::Override._early.each do |args|
40
+ Deface::Override.new(args)
41
+ end
42
+
43
+ Deface::Override._early.clear
44
+ end
45
+
46
+ private
47
+ def enumerate_and_load(paths, root)
48
+ paths ||= ["app/overrides"]
49
+
50
+ paths.each do |path|
51
+ Dir.glob(root.join path, "*.rb") do |c|
52
+ Rails.application.config.cache_classes ? require(c) : load(c)
53
+ end
24
54
  end
25
55
 
26
- Deface::Override._early.clear
27
56
  end
28
57
  end
29
58
  end
@@ -6,7 +6,7 @@ module Deface
6
6
  attr_accessor :args
7
7
 
8
8
  @@_early = []
9
- @@actions = [:remove, :replace, :replace_contents, :insert_after, :insert_before, :insert_top, :insert_bottom, :set_attributes]
9
+ @@actions = [:remove, :replace, :replace_contents, :surround, :surround_contents, :insert_after, :insert_before, :insert_top, :insert_bottom, :set_attributes]
10
10
  @@sources = [:text, :partial, :template]
11
11
 
12
12
  # Initializes new override, you must supply only one Target, Action & Source
@@ -23,6 +23,8 @@ module Deface
23
23
  # * <tt>:remove</tt> - Removes all elements that match the supplied selector
24
24
  # * <tt>:replace</tt> - Replaces all elements that match the supplied selector
25
25
  # * <tt>:replace_contents</tt> - Replaces the contents of all elements that match the supplied selector
26
+ # * <tt>:surround</tt> - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
27
+ # * <tt>:surround_contents</tt> - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
26
28
  # * <tt>:insert_after</tt> - Inserts after all elements that match the supplied selector
27
29
  # * <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
28
30
  # * <tt>:insert_top</tt> - Inserts inside all elements that match the supplied selector, before all existing child
@@ -59,7 +61,7 @@ module Deface
59
61
  # * <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
60
62
  #
61
63
  def initialize(args)
62
- unless Rails.application.try(:config).try(:deface)
64
+ unless Rails.application.try(:config).respond_to?(:deface) and Rails.application.try(:config).deface.try(:overrides)
63
65
  @@_early << args
64
66
  warn "[WARNING] Deface railtie has not initialized yet, override '#{args[:name]}' is being declared too early."
65
67
  return
@@ -92,6 +94,7 @@ module Deface
92
94
  else
93
95
  #initializing new override
94
96
  @args = args
97
+
95
98
  raise(ArgumentError, ":action is invalid") if self.action.nil?
96
99
  end
97
100
 
@@ -235,6 +238,23 @@ module Deface
235
238
  when :replace_contents
236
239
  match.children.remove
237
240
  match.add_child(override.source_element)
241
+ when :surround, :surround_contents
242
+
243
+ new_source = override.source_element.clone(1)
244
+
245
+ if original = new_source.css("code:contains('render_original')").first
246
+ if override.action == :surround
247
+ original.replace match.clone(1)
248
+ match.replace new_source
249
+ elsif override.action == :surround_contents
250
+ original.replace match.children
251
+ match.children.remove
252
+ match.add_child new_source
253
+ end
254
+ else
255
+ #maybe we should log that the original wasn't found.
256
+ end
257
+
238
258
  when :insert_before
239
259
  match.before override.source_element
240
260
  when :insert_after
@@ -316,6 +336,8 @@ module Deface
316
336
  virtual_path = details[:virtual_path]
317
337
  return [] if virtual_path.nil?
318
338
 
339
+ virtual_path = virtual_path[1..-1] if virtual_path.first == '/'
340
+
319
341
  result = []
320
342
  result << self.all[virtual_path.to_sym].try(:values)
321
343
 
@@ -1,12 +1,67 @@
1
1
  module Deface
2
2
  class Railtie < Rails::Railtie
3
+ # include rake tasks.
4
+ #
3
5
  rake_tasks do
4
- load File.join([File.dirname(__FILE__) , "../../tasks/deface.rake"])
6
+ %w{utils precompile}.each { |r| load File.join([File.dirname(__FILE__) , "../../tasks/#{r}.rake"]) }
5
7
  end
6
8
 
7
- initializer "deface.environment" do |app|
9
+ def self.activate
10
+ if Rails.application.config.deface.enabled
11
+ #load all overrides
12
+ Rails.application.config.deface.overrides.load_all Rails.application
13
+ end
14
+
15
+ end
16
+
17
+ config.to_prepare &method(:activate).to_proc
18
+
19
+ # configures basic deface environment, with gets replaced
20
+ # with real environment if deface is not disabled
21
+ #
22
+ initializer "deface.add_configuration", :before => :load_environment_config do |app|
23
+ app.config.deface = ActiveSupport::OrderedOptions.new
24
+ app.config.deface.enabled = true
25
+ end
26
+
27
+ # injects path for compiled views
28
+ #
29
+ initializer "deface.precompile.inject_views", :before => :add_view_paths do |app|
30
+ app.paths["app/views"].unshift "app/compiled_views"
31
+ end
32
+
33
+ # remove app/overrides from eager_load_path for app and all railites
34
+ # as we require them manually depending on configuration values
35
+ #
36
+ initializer "deface.tweak_eager_loading", :before => :set_load_path do |app|
37
+
38
+ # application
39
+ app.config.eager_load_paths.reject! {|path| path =~ /app\/overrides\z/ }
40
+
41
+ # railites / engines / extensions
42
+ app.railties.all.each do |railtie|
43
+ next unless railtie.respond_to? :root
44
+
45
+ railtie.config.eager_load_paths.reject! {|path| path =~ /app\/overrides\z/ }
46
+ end
47
+ end
48
+
49
+ # sets up deface environment and requires / loads all
50
+ # overrides if deface is enabled.
51
+ #
52
+ initializer "deface.environment", :after => :load_environment_config do |app|
53
+ next unless app.config.deface.enabled
54
+
55
+ #setup real env object
8
56
  app.config.deface = Deface::Environment.new
57
+
58
+ #catchs any overrides that we required manually
9
59
  app.config.deface.overrides.early_check
60
+
61
+ if Dir.glob(app.root.join("app/compiled_views", "**/*.erb")).present?
62
+ puts "[WARNING] Precompiled views present and Deface is enabled, this can result in overrides being applied twice."
63
+ end
10
64
  end
65
+
11
66
  end
12
67
  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, include_overrides=true)
5
+ def load_template_source(virtual_path, partial, apply_overrides=true)
6
6
  parts = virtual_path.split("/")
7
7
  prefix = []
8
8
  if parts.size == 2
@@ -13,15 +13,9 @@ module Deface
13
13
  name = parts.join("/")
14
14
  end
15
15
 
16
+ Rails.application.config.deface.enabled = apply_overrides
16
17
  @lookup_context ||= ActionView::LookupContext.new(ActionController::Base.view_paths, {:formats => [:html]})
17
-
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
18
+ @lookup_context.find(name, prefix, partial).source
25
19
  end
26
20
 
27
21
  #gets source erb for an element
@@ -29,6 +29,73 @@ module Deface
29
29
  it "should find overrides" do
30
30
  Rails.application.config.deface.overrides.find(:virtual_path => "posts/new").size.should == 1
31
31
  end
32
+
33
+ describe "load_all" do
34
+
35
+ before do
36
+ Rails.application.stub :root => Pathname.new(File.join(File.dirname(__FILE__), '..', "assets"))
37
+ Rails.application.stub :paths => {}
38
+ Rails.application.stub_chain :railties, :all => []
39
+ end
40
+
41
+ it "should enumerate_and_load nil when app has no app/overrides path set" do
42
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
43
+ Rails.application.config.deface.overrides.load_all(Rails.application)
44
+ end
45
+
46
+ it "should enumerate_and_load path when app has app/overrides path set" do
47
+ Rails.application.stub :paths => {"app/overrides" => ["app/some_path"] }
48
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , Rails.application.root)
49
+ Rails.application.config.deface.overrides.load_all(Rails.application)
50
+ end
51
+
52
+ it "should enumerate_and_load nil when railtie has no app/overrides path set" do
53
+ Rails.application.stub_chain :railties, :all => [mock('railtie', :root => "/some/path")]
54
+
55
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
56
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, "/some/path")
57
+ Rails.application.config.deface.overrides.load_all(Rails.application)
58
+ end
59
+
60
+ it "should enumerate_and_load path when railtie has app/overrides path set" do
61
+ Rails.application.stub_chain :railties, :all => [ mock('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
62
+
63
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
64
+ Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , "/some/path")
65
+ Rails.application.config.deface.overrides.load_all(Rails.application)
66
+ end
67
+
68
+ it "should ignore railtie with no root" do
69
+ railtie = mock('railtie')
70
+ Rails.application.stub_chain :railties, :all => [railtie]
71
+
72
+ railtie.should_receive(:respond_to?).with(:root)
73
+ railtie.should_not_receive(:respond_to?).with(:paths)
74
+ Rails.application.config.deface.overrides.load_all(Rails.application)
75
+ end
76
+
77
+ end
78
+
79
+ describe "enumerate_and_load" do
80
+ let(:root) { Pathname.new("/some/path") }
81
+
82
+ it "should be enumerate default path when none supplied" do
83
+ Dir.should_receive(:glob).with(root.join "app/overrides", "*.rb")
84
+ Rails.application.config.deface.overrides.send(:enumerate_and_load, nil, root)
85
+ end
86
+
87
+ it "should be enumerate supplied path" do
88
+ Dir.should_receive(:glob).with(root.join "app/junk", "*.rb")
89
+ Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/junk"], root)
90
+ end
91
+
92
+ it "should be enumerate supplied paths" do
93
+ Dir.should_receive(:glob).with(root.join "app/junk", "*.rb" )
94
+ Dir.should_receive(:glob).with(root.join "app/gold", "*.rb" )
95
+ Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/junk", "app/gold"], root)
96
+ end
97
+
98
+ end
32
99
  end
33
100
 
34
101
  describe "#_early" do
@@ -13,7 +13,7 @@ module Deface
13
13
 
14
14
  describe "with no overrides defined" do
15
15
  it "should return source for partial" do
16
- load_template_source("shared/_post", false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
16
+ load_template_source("shared/post", true).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
17
17
  end
18
18
 
19
19
  it "should return source for template" do
@@ -25,7 +25,7 @@ module Deface
25
25
  end
26
26
 
27
27
  it "should raise exception for non-existing file" do
28
- lambda { load_template_source("tester/_post", false) }.should raise_error(ActionView::MissingTemplate)
28
+ lambda { load_template_source("tester/post", true) }.should raise_error(ActionView::MissingTemplate)
29
29
  end
30
30
 
31
31
  end
@@ -40,11 +40,11 @@ module Deface
40
40
  end
41
41
 
42
42
  it "should return source for partial including overrides" do
43
- load_template_source("shared/_post", false).should == "\n<%= \"And I've got ERB\" %>"
43
+ load_template_source("shared/post", true).should == "\n<%= \"And I've got ERB\" %>"
44
44
  end
45
45
 
46
46
  it "should return source for partial excluding overrides" do
47
- load_template_source("shared/_post", false, false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
47
+ load_template_source("shared/post", true, false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
48
48
  end
49
49
 
50
50
  it "should return source for template including overrides" do
@@ -209,6 +209,51 @@ module ActionView
209
209
  end
210
210
  end
211
211
 
212
+
213
+ describe "with a single html surround override defined" do
214
+ before(:each) do
215
+ Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<h1>It's behind you!</h1><div><%= render_original %></div>")
216
+ @template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
217
+ end
218
+
219
+ it "should return modified source" do
220
+ @template.source.should == "<h1>It's behind you!</h1><div><p>test</p></div>"
221
+ end
222
+ end
223
+
224
+ describe "with a single erb surround override defined" do
225
+ before(:each) do
226
+ Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround => "p", :text => "<% some_method('test') do %><%= render_original %><% end %>")
227
+ @template = ActionView::Template.new("<span><p>test</p></span>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
228
+ end
229
+
230
+ it "should return modified source" do
231
+ @template.source.gsub("\n", '').should == "<span><% some_method('test') do %><p>test</p><% end %></span>"
232
+ end
233
+ end
234
+
235
+ describe "with a single html surround_contents override defined" do
236
+ before(:each) do
237
+ Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "div", :text => "<span><%= render_original %></span>")
238
+ @template = ActionView::Template.new("<h4>yay!</h4><div><p>test</p></div>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
239
+ end
240
+
241
+ it "should return modified source" do
242
+ @template.source.should == "<h4>yay!</h4><div><span><p>test</p></span></div>"
243
+ end
244
+ end
245
+
246
+ describe "with a single erb surround_contents override defined" do
247
+ before(:each) do
248
+ Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :surround_contents => "p", :text => "<% if 1==1 %><%= render_original %><% end %>")
249
+ @template = ActionView::Template.new("<p>test</p>", "/some/path/to/file.erb", ActionView::Template::Handlers::ERB, {:virtual_path=>"posts/index", :format=>:html})
250
+ end
251
+
252
+ it "should return modified source" do
253
+ @template.source.should == "<p><% if 1==1 %>test<% end %></p>"
254
+ end
255
+ end
256
+
212
257
  describe "with a single disabled override defined" do
213
258
  before(:each) do
214
259
  Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "<h1>Argh!</h1>", :disabled => true)
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,8 @@ shared_context "mock Rails" do
16
16
  Rails.stub :application => mock('application')
17
17
  Rails.application.stub :config => mock('config')
18
18
  Rails.application.config.stub :cache_classes => true
19
- Rails.application.config.stub :deface => nil
19
+ Rails.application.config.stub :deface => ActiveSupport::OrderedOptions.new
20
+ Rails.application.config.deface.enabled = true
20
21
  end
21
22
  end
22
23
 
@@ -0,0 +1,40 @@
1
+ require 'deface'
2
+
3
+ namespace :deface do
4
+ include Deface::TemplateHelper
5
+
6
+ desc "Precompiles overrides into template files"
7
+ task :precompile => [:environment, :clean] do |t, args|
8
+ base_path = Rails.root.join("app/compiled_views")
9
+
10
+ # temporarily configures deface env and loads
11
+ # all overrides so we can precompile
12
+ unless Rails.application.config.deface.enabled
13
+ Rails.application.config.deface = Deface::Environment.new
14
+ Rails.application.config.deface.overrides.early_check
15
+ Rails.application.config.deface.overrides.load_all Rails.application
16
+ end
17
+
18
+ Rails.application.config.deface.overrides.all.each do |virtual_path,overrides|
19
+ template_path = base_path.join( "#{virtual_path}.html.erb")
20
+
21
+ FileUtils.mkdir_p template_path.dirname
22
+ begin
23
+ source = load_template_source(virtual_path.to_s, false, true)
24
+ if source.blank?
25
+ raise "Compiled source was blank for '#{virtual_path}'"
26
+ end
27
+ File.open(template_path, 'w') {|f| f.write source }
28
+ rescue Exception => e
29
+ puts "Unable to precompile '#{virtual_path}' due to: "
30
+ puts e.message
31
+ end
32
+ end
33
+ end
34
+
35
+ desc "Removes all precompiled override templates"
36
+ task :clean do
37
+ FileUtils.rm_rf Rails.root.join("app/compiled_views")
38
+ end
39
+
40
+ end
File without changes
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
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-10-05 00:00:00 Z
18
+ date: 2011-10-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: nokogiri
@@ -57,12 +57,12 @@ dependencies:
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- hash: 23
60
+ hash: 19
61
61
  segments:
62
62
  - 2
63
- - 6
63
+ - 7
64
64
  - 0
65
- version: 2.6.0
65
+ version: 2.7.0
66
66
  type: :development
67
67
  version_requirements: *id003
68
68
  description: Deface is a library that allows you to customize ERB views in a Rails application without editing the underlying view.
@@ -97,7 +97,8 @@ files:
97
97
  - spec/deface/template_helper_spec.rb
98
98
  - spec/deface/template_spec.rb
99
99
  - spec/spec_helper.rb
100
- - tasks/deface.rake
100
+ - tasks/precompile.rake
101
+ - tasks/utils.rake
101
102
  homepage: http://github.com/railsdog/deface
102
103
  licenses: []
103
104