more hacking
This commit is contained in:
parent
936372cb57
commit
b1e99d46c6
@ -17,7 +17,7 @@ module Flowerbox::Delivery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add(asset)
|
def add(asset)
|
||||||
paths_for(asset).each { |path| @files.add(path_for_compiled_asset(path)) }
|
paths_for(asset).each { |path| add_paths_for_compiled_asset(path) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def paths_for(asset)
|
def paths_for(asset)
|
||||||
@ -29,6 +29,7 @@ module Flowerbox::Delivery
|
|||||||
|
|
||||||
@environment = Sprockets::Environment.new
|
@environment = Sprockets::Environment.new
|
||||||
@environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
@environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
||||||
|
@environment.register_postprocessor('application/javascript', Flowerbox::Delivery::Tilt::EnsureSavedFile)
|
||||||
@environment.unregister_bundle_processor('text/css', Sprockets::CharsetNormalizer)
|
@environment.unregister_bundle_processor('text/css', Sprockets::CharsetNormalizer)
|
||||||
@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
|
@environment.register_engine('.js', Flowerbox::Delivery::Tilt::JSTemplate)
|
||||||
@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
|
@environment.register_engine('.css', Flowerbox::Delivery::Tilt::CSSTemplate)
|
||||||
@ -43,8 +44,8 @@ module Flowerbox::Delivery
|
|||||||
environment.find_asset(*args)
|
environment.find_asset(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_for_compiled_asset(path)
|
def add_paths_for_compiled_asset(path)
|
||||||
Pathname(asset_for(path, :bundle => false).to_s)
|
asset_for(path, :bundle => false).to_a.each { |file_path| @files.add(file_path) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,5 +6,7 @@ module Flowerbox::Delivery::Tilt
|
|||||||
autoload :CSSTemplate, 'flowerbox/delivery/tilt/css_template'
|
autoload :CSSTemplate, 'flowerbox/delivery/tilt/css_template'
|
||||||
|
|
||||||
autoload :TemplateThatSaves, 'flowerbox/delivery/tilt/template_that_saves'
|
autoload :TemplateThatSaves, 'flowerbox/delivery/tilt/template_that_saves'
|
||||||
|
|
||||||
|
autoload :EnsureSavedFile, 'flowerbox/delivery/tilt/ensure_saved_file'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,9 +6,5 @@ class Flowerbox::Delivery::Tilt::CSSTemplate < Tilt::Template
|
|||||||
EXTENSION = "css"
|
EXTENSION = "css"
|
||||||
|
|
||||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
|
||||||
handle_evaluate
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
22
lib/flowerbox/delivery/tilt/ensure_saved_file.rb
Normal file
22
lib/flowerbox/delivery/tilt/ensure_saved_file.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'tilt'
|
||||||
|
|
||||||
|
module Flowerbox::Delivery::Tilt
|
||||||
|
class EnsureSavedFile < Tilt::Template
|
||||||
|
include TemplateThatSaves
|
||||||
|
|
||||||
|
def handle_evaluate
|
||||||
|
output = if File.file?(data)
|
||||||
|
data
|
||||||
|
else
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def extension
|
||||||
|
"js"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -6,9 +6,5 @@ class Flowerbox::Delivery::Tilt::JSTemplate < Tilt::Template
|
|||||||
EXTENSION = "js"
|
EXTENSION = "js"
|
||||||
|
|
||||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||||
|
|
||||||
def evaluate(scope, locals, &block)
|
|
||||||
handle_evaluate
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,7 +18,15 @@ module Flowerbox::Delivery::Tilt::TemplateThatSaves
|
|||||||
end
|
end
|
||||||
|
|
||||||
def temp_file
|
def temp_file
|
||||||
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{self.class::EXTENSION})(.*)$}, '\1'))
|
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{extension})(.*)$}, '\1'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
handle_evaluate
|
||||||
|
end
|
||||||
|
|
||||||
|
def extension
|
||||||
|
self.class::EXTENSION
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,6 +4,10 @@ module Flowerbox::Delivery
|
|||||||
[ files ].flatten.each { |file| self << file if !include?(file) }
|
[ files ].flatten.each { |file| self << file if !include?(file) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_json
|
||||||
|
collect(&:body)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def include?(file)
|
def include?(file)
|
||||||
any? { |other_file| other_file == file }
|
any? { |other_file| other_file == file }
|
||||||
|
Loading…
Reference in New Issue
Block a user