Class: Barista::Framework
- Inherits:
-
Object
- Object
- Barista::Framework
- Defined in:
- lib/barista/framework.rb
Instance Attribute Summary collapse
-
#framework_root ⇒ Object
readonly
Returns the value of attribute framework_root.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_prefix ⇒ Object
Returns the value of attribute output_prefix.
Class Method Summary collapse
- .[](name) ⇒ Object
- .all(include_default = false) ⇒ Object
- .coffeescript_glob_paths ⇒ Object
- .default_framework ⇒ Object
- .default_framework=(value) ⇒ Object
- .exposed_coffeescripts ⇒ Object
- .full_path_for(script) ⇒ Object
- .register(name, root) ⇒ Object
Instance Method Summary collapse
- #coffeescript_glob_path ⇒ Object
- #coffeescripts ⇒ Object
- #exposed_coffeescripts ⇒ Object
- #full_path_for(name) ⇒ Object
-
#initialize(options, root = nil, output_prefix = nil) ⇒ Framework
constructor
A new instance of Framework.
- #output_path_for(file, format = 'js') ⇒ Object
- #output_root ⇒ Object
- #short_name(script) ⇒ Object
Constructor Details
#initialize(options, root = nil, output_prefix = nil) ⇒ Framework
Returns a new instance of Framework.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/barista/framework.rb', line 48 def initialize(, root = nil, output_prefix = nil) unless .is_a?(Hash) Barista.deprecate! self, "initialize(name, root = nil, output_prefix = nil)", "Please use the option syntax instead." = { :name => , :root => root, :output_prefix => output_prefix } end # actually setup the framework. , :name, :root @name = [:name].to_s @output_prefix = [:output_prefix] @framework_root = File.([:root].to_s) @output_root = [:output_root] && Pathname([:output_root]) end |
Instance Attribute Details
#framework_root ⇒ Object (readonly)
Returns the value of attribute framework_root.
46 47 48 |
# File 'lib/barista/framework.rb', line 46 def framework_root @framework_root end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/barista/framework.rb', line 46 def name @name end |
#output_prefix ⇒ Object
Returns the value of attribute output_prefix.
46 47 48 |
# File 'lib/barista/framework.rb', line 46 def output_prefix @output_prefix end |
Class Method Details
.[](name) ⇒ Object
41 42 43 44 |
# File 'lib/barista/framework.rb', line 41 def self.[](name) name = name.to_s (@all ||= []).detect { |fw| fw.name == name } end |
.all(include_default = false) ⇒ Object
12 13 14 15 16 |
# File 'lib/barista/framework.rb', line 12 def self.all(include_default = false) (@all ||= []).dup.tap do |all| all.unshift default_framework if include_default end end |
.coffeescript_glob_paths ⇒ Object
24 25 26 |
# File 'lib/barista/framework.rb', line 24 def self.coffeescript_glob_paths all(true).map { |fw| fw.coffeescript_glob_path } end |
.default_framework ⇒ Object
4 5 6 |
# File 'lib/barista/framework.rb', line 4 def self.default_framework @default_framework ||= self.new(:name => "default", :root => Barista.root) end |
.default_framework=(value) ⇒ Object
8 9 10 |
# File 'lib/barista/framework.rb', line 8 def self.default_framework=(value) @default_framework = value end |
.exposed_coffeescripts ⇒ Object
18 19 20 21 22 |
# File 'lib/barista/framework.rb', line 18 def self.exposed_coffeescripts all(true).inject([]) do |collection, fw| collection + fw.exposed_coffeescripts end.uniq.sort_by { |f| f.length } end |
.full_path_for(script) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/barista/framework.rb', line 28 def self.full_path_for(script) script = script.to_s.gsub(/\.js$/, '.coffee').gsub(/^\/+/, '') all(true).each do |fw| full_path = fw.full_path_for(script) return full_path, fw if full_path end nil end |
Instance Method Details
#coffeescript_glob_path ⇒ Object
69 70 71 |
# File 'lib/barista/framework.rb', line 69 def coffeescript_glob_path @coffeescript_glob_path ||= File.join(@framework_root, "**", "*.coffee") end |
#coffeescripts ⇒ Object
65 66 67 |
# File 'lib/barista/framework.rb', line 65 def coffeescripts Dir[coffeescript_glob_path] end |
#exposed_coffeescripts ⇒ Object
78 79 80 |
# File 'lib/barista/framework.rb', line 78 def exposed_coffeescripts coffeescripts.map { |script| short_name(script) } end |
#full_path_for(name) ⇒ Object
87 88 89 90 |
# File 'lib/barista/framework.rb', line 87 def full_path_for(name) full_path = File.join(@framework_root, remove_prefix(name, @output_prefix.to_s)) File.exist?(full_path) ? full_path : nil end |
#output_path_for(file, format = 'js') ⇒ Object
96 97 98 99 100 |
# File 'lib/barista/framework.rb', line 96 def output_path_for(file, format = 'js') # Strip the leading slashes file = file.to_s.gsub(/^\/+/, '') output_root.join(file).to_s.gsub(/\.[^\.]+$/, ".#{format}") end |
#output_root ⇒ Object
92 93 94 |
# File 'lib/barista/framework.rb', line 92 def output_root @output_root || Barista.output_root end |
#short_name(script) ⇒ Object
73 74 75 76 |
# File 'lib/barista/framework.rb', line 73 def short_name(script) short_name = remove_prefix script, @framework_root File.join(*[@output_prefix, short_name].compact) end |