so that almost preps the project for being merged back into the flowerbox gem proper...
This commit is contained in:
parent
624e9007f3
commit
4b6c09c7bc
@ -1,11 +1,8 @@
|
||||
module Flowerbox
|
||||
module Delivery
|
||||
autoload :Server, 'flowerbox/delivery/server'
|
||||
autoload :TemplateRenderer, 'flowerbox/delivery/template_renderer'
|
||||
autoload :SprocketsHandler, 'flowerbox/delivery/sprockets_handler'
|
||||
autoload :UniqueAssetList, 'flowerbox/delivery/unique_asset_list'
|
||||
|
||||
autoload :Tilt, 'flowerbox/delivery/tilt'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
require 'erb'
|
||||
|
||||
module Flowerbox::Delivery
|
||||
class TemplateRenderer
|
||||
class FileTypeError < StandardError ; end
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def render
|
||||
ERB.new(template).result(binding)
|
||||
end
|
||||
|
||||
def template
|
||||
File.read(options[:template])
|
||||
end
|
||||
|
||||
def resource_tags
|
||||
options[:files].collect do |file|
|
||||
case File.extname(file)
|
||||
when '.js'
|
||||
%{<script src="#{file}" type="text/javascript"></script>}
|
||||
when '.css'
|
||||
%{<link rel="stylesheet" href="#{file}" type="text/css" />}
|
||||
else
|
||||
raise FileTypeError.new("Unknown file type: #{File.extname(file)} for #{file}")
|
||||
end
|
||||
end.join
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +0,0 @@
|
||||
require 'sprockets'
|
||||
|
||||
module Flowerbox::Delivery::Tilt
|
||||
autoload :JSTemplate, 'flowerbox/delivery/tilt/js_template'
|
||||
autoload :JSTTemplate, 'flowerbox/delivery/tilt/jst_template'
|
||||
autoload :CSSTemplate, 'flowerbox/delivery/tilt/css_template'
|
||||
|
||||
autoload :TemplateThatSaves, 'flowerbox/delivery/tilt/template_that_saves'
|
||||
|
||||
autoload :EnsureSavedFile, 'flowerbox/delivery/tilt/ensure_saved_file'
|
||||
end
|
||||
|
@ -1,11 +0,0 @@
|
||||
require 'tilt'
|
||||
|
||||
class Flowerbox::Delivery::Tilt::CSSTemplate < Tilt::Template
|
||||
self.default_mime_type = "text/css"
|
||||
|
||||
EXTENSION = "css"
|
||||
|
||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||
|
||||
end
|
||||
|
@ -1,22 +0,0 @@
|
||||
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
|
||||
|
@ -1,14 +0,0 @@
|
||||
require 'tilt'
|
||||
|
||||
class Flowerbox::Delivery::Tilt::JSTemplate < Tilt::Template
|
||||
self.default_mime_type = "application/javascript"
|
||||
|
||||
EXTENSION = "js"
|
||||
|
||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
handle_evaluate
|
||||
end
|
||||
end
|
||||
|
@ -1,20 +0,0 @@
|
||||
require 'tilt'
|
||||
|
||||
class Flowerbox::Delivery::Tilt::JSTTemplate < Sprockets::JstProcessor
|
||||
EXTENSION = "jst"
|
||||
|
||||
include Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
@data = super
|
||||
|
||||
p @data
|
||||
|
||||
handle_evaluate
|
||||
end
|
||||
|
||||
def data_to_save
|
||||
@data || data
|
||||
end
|
||||
end
|
||||
|
@ -1,36 +0,0 @@
|
||||
module Flowerbox::Delivery::Tilt::TemplateThatSaves
|
||||
def prepare ; end
|
||||
|
||||
def handle_evaluate
|
||||
case File.extname(file)
|
||||
when '.js'
|
||||
file
|
||||
else
|
||||
save
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
FileUtils.mkdir_p File.dirname(temp_file)
|
||||
File.open(temp_file, 'wb') { |fh| fh.print data_to_save }
|
||||
|
||||
temp_file
|
||||
end
|
||||
|
||||
def data_to_save
|
||||
data
|
||||
end
|
||||
|
||||
def temp_file
|
||||
File.join(Dir.pwd, ".tmp/sprockets", file.gsub(%r{(\.#{extension})(.*)$}, '\1'))
|
||||
end
|
||||
|
||||
def extension
|
||||
self.class::EXTENSION
|
||||
end
|
||||
|
||||
def evaluate(scope, locals, &block)
|
||||
handle_evaluate
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user