lib/barista/framework.rb in barista-0.2.0 vs lib/barista/framework.rb in barista-0.2.1
- old
+ new
@@ -7,54 +7,74 @@
def self.default_framework=(value)
@default_framework = value
end
- def self.all
- [default_framework] + (@all ||= [])
+ def self.all(include_default = false)
+ all = (@all ||= [])
+ all = [default_framework] + all if include_default
+ all
end
def self.exposed_coffeescripts
- all.inject([]) do |collection, fw|
+ all(true).inject([]) do |collection, fw|
collection + fw.exposed_coffeescripts
- end.uniq
+ end.uniq.sort_by { |f| f.length }
end
def self.full_path_for(script)
script = script.to_s.gsub(/\.js$/, '.coffee').gsub(/^\/+/, '')
- all.each do |fw|
+ all(true).each do |fw|
full_path = fw.full_path_for(script)
return full_path, fw if full_path
end
nil
end
def self.register(name, root)
(@all ||= []) << self.new(name, root)
end
- attr_reader :name, :framework_root
+ def self.[](name)
+ name = name.to_s
+ (@all ||= []).detect { |fw| fw.name == name }
+ end
- def initialize(name, root)
- @name = name
+ attr_reader :name, :framework_root, :output_prefix
+
+ def initialize(name, root, output_prefix = nil)
+ @name = name.to_s
+ @output_prefix = nil
@framework_root = File.expand_path(root)
end
def coffeescripts
Dir[File.join(@framework_root, "**", "*.coffee")]
end
def short_name(script)
- File.expand_path(script).gsub /^#{Regexp.escape(@framework_root)}\/?/, ''
+ short_name = remove_prefix script, @framework_root
+ File.join *[@output_prefix, short_name].compact
end
def exposed_coffeescripts
coffeescripts.map { |script| short_name(script) }
end
+ def output_prefix=(value)
+ value = value.to_s.gsub /(^\/|\/$)/, ''
+ @output_prefix = value.blank? ? nil : value
+ end
+
def full_path_for(name)
- full_path = File.join(@framework_root, name)
+ full_path = File.join(@framework_root, remove_prefix(name, @output_prefix.to_s))
File.exist?(full_path) ? full_path : nil
+ end
+
+ protected
+
+ def remove_prefix(path, prefix)
+ path.to_s.gsub /^#{Regexp.escape(prefix.to_s)}\/?/, ''
end
end
end
\ No newline at end of file