class Asset
Constants
- SYNTAX
Public Class Methods
helper_port=(port)
click to toggle source
# File lib/tags/asset.rb, line 39 def self.helper_port=(port) @@helper_port = port end
new(tag_name, markup, tokens)
click to toggle source
Calls superclass method
# File lib/tags/asset.rb, line 19 def initialize(tag_name, markup, tokens) super raise AssetError, 'Invalid layout syntax' unless markup =~ SYNTAX @path = parse_expression(Regexp.last_match(1)) # This is defaulted to the pages dir, because it represents the structure # of our website. Asset directories are copied as siblings at runtime. @@root_dir ||= File.join(Dir.pwd, 'pages') @attributes = {} markup.scan(Liquid::TagAttributes) do |key, value| @attributes[key] = parse_expression(value) end end
root_dir=(dir)
click to toggle source
# File lib/tags/asset.rb, line 35 def self.root_dir=(dir) @@root_dir = dir end
Public Instance Methods
render_to_output_buffer(context, output)
click to toggle source
# File lib/tags/asset.rb, line 43 def render_to_output_buffer(context, output) path = @path path = path.evaluate(context) if path.is_a? Liquid::VariableLookup unless @@root_dir raise AssetError, 'root_dir must be set on Archival::Asset' end unless context.key? 'template_path' raise AssetError, 'template_path must be provided to parse when using assets' end template_path = File.dirname(context['template_path']) abs_asset_path = Pathname.new(File.join(@@root_dir, path)) asset_path = abs_asset_path.relative_path_from(template_path).cleanpath.to_s output << if @attributes['serve'] == true "http://localhost:#{@@helper_port}/#{asset_path}" else asset_path end output end