class MagLove::Asset::Theme
Constants
- OUTPUT_MAPPING
Attributes
contents[R]
mtime[R]
options[R]
path[R]
valid[R]
Public Class Methods
new(path, options = {})
click to toggle source
# File lib/maglove/asset/theme.rb, line 26 def initialize(path, options = {}) @path = path @options = options @options[:theme] = Maglove.theme.identifier @mtime = File.mtime(absolute_path) begin if ::Tilt[input_type] template = ::Tilt.new(absolute_path) @contents = template.render(Object.new, @options.merge(base_path: "src/base/#{Maglove.theme.base_version}/")) else @contents = File.read(absolute_path) end rescue Maglove::Engine::RenderError => e error("▸ HAML error: #{e.message}") end end
Public Instance Methods
absolute_path()
click to toggle source
# File lib/maglove/asset/theme.rb, line 70 def absolute_path if @options[:base] Maglove.theme.base_dir.file(path).absolute_path else Maglove.theme.src_dir.file(path).absolute_path end end
input_type()
click to toggle source
# File lib/maglove/asset/theme.rb, line 43 def input_type File.extname(path).delete("\.") end
logical_path()
click to toggle source
# File lib/maglove/asset/theme.rb, line 78 def logical_path return false unless valid? dirname = File.dirname(path) if dirname == "/" "#{File.basename(path, '.*')}.#{output_type}" else "#{dirname}/#{File.basename(path, '.*')}.#{output_type}" end end
output_path()
click to toggle source
# File lib/maglove/asset/theme.rb, line 88 def output_path return false unless valid? "dist/themes/#{@options[:theme]}/#{logical_path}" end
output_type()
click to toggle source
# File lib/maglove/asset/theme.rb, line 47 def output_type OUTPUT_MAPPING[input_type] or input_type end
valid?()
click to toggle source
# File lib/maglove/asset/theme.rb, line 51 def valid? !contents.nil? end
write!()
click to toggle source
# File lib/maglove/asset/theme.rb, line 55 def write! write_to!(output_path) end
write_to!(path)
click to toggle source
# File lib/maglove/asset/theme.rb, line 59 def write_to!(path) return false unless valid? FileUtils.mkdir_p(File.dirname(path)) File.open("#{path}+", 'wb') { |f| f.write @contents } FileUtils.mv("#{path}+", path) File.utime(mtime, mtime, path) true ensure FileUtils.rm("#{path}+") if File.exist?("#{path}+") end