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
- .exposed_javascripts ⇒ Object
- .full_path_for(script) ⇒ Object
- .register(name, options = nil) ⇒ Object
Instance Method Summary collapse
- #coffeescript_glob_path ⇒ Object
- #coffeescripts ⇒ Object
- #exposed_coffeescripts ⇒ Object
- #exposed_javascripts ⇒ Object
- #full_path_for(name) ⇒ Object
-
#initialize(options, root = nil, output_prefix = nil) ⇒ Framework
constructor
A new instance of Framework.
- #javascript_glob_path ⇒ Object
- #javascripts ⇒ Object
- #output_path_for(file, format = 'js') ⇒ Object
- #output_root ⇒ Object
- #output_root=(value) ⇒ Object
- #short_name(script) ⇒ Object
Constructor Details
#initialize(options, root = nil, output_prefix = nil) ⇒ Framework
Returns a new instance of Framework.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/barista/framework.rb', line 60 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) self.output_root = [:output_root] end |
Instance Attribute Details
#framework_root ⇒ Object (readonly)
Returns the value of attribute framework_root.
58 59 60 |
# File 'lib/barista/framework.rb', line 58 def framework_root @framework_root end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
58 59 60 |
# File 'lib/barista/framework.rb', line 58 def name @name end |
#output_prefix ⇒ Object
Returns the value of attribute output_prefix.
58 59 60 |
# File 'lib/barista/framework.rb', line 58 def output_prefix @output_prefix end |
Class Method Details
.[](name) ⇒ Object
53 54 55 56 |
# File 'lib/barista/framework.rb', line 53 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
30 31 32 |
# File 'lib/barista/framework.rb', line 30 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 |
.exposed_javascripts ⇒ Object
24 25 26 27 28 |
# File 'lib/barista/framework.rb', line 24 def self.exposed_javascripts all(true).inject([]) do |collection, fw| collection + fw.exposed_javascripts end.uniq.sort_by { |f| f.length } end |
.full_path_for(script) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/barista/framework.rb', line 34 def self.full_path_for(script) javascript = script.to_s.gsub(/\.coffee$/, '.js').gsub(/^\/+/, '') coffeescript = script.to_s.gsub(/\.js$/, '.coffee').gsub(/^\/+/, '') all(true).each do |fw| full_path = fw.full_path_for(coffeescript) || fw.full_path_for(javascript) return full_path, fw if full_path end nil end |
.register(name, options = nil) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/barista/framework.rb', line 44 def self.register(name, = nil) if .is_a?(Hash) framework = self.new(.merge(:name => name)) else framework = self.new(:name => name, :root => ) end (@all ||= []) << framework end |
Instance Method Details
#coffeescript_glob_path ⇒ Object
85 86 87 |
# File 'lib/barista/framework.rb', line 85 def coffeescript_glob_path @coffeescript_glob_path ||= File.join(@framework_root, "**", "*.coffee") end |
#coffeescripts ⇒ Object
77 78 79 |
# File 'lib/barista/framework.rb', line 77 def coffeescripts Dir[coffeescript_glob_path] end |
#exposed_coffeescripts ⇒ Object
98 99 100 |
# File 'lib/barista/framework.rb', line 98 def exposed_coffeescripts coffeescripts.map { |script| short_name(script) } end |
#exposed_javascripts ⇒ Object
102 103 104 |
# File 'lib/barista/framework.rb', line 102 def exposed_javascripts javascripts.map { |script| short_name(script) } end |
#full_path_for(name) ⇒ Object
111 112 113 114 |
# File 'lib/barista/framework.rb', line 111 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 |
#javascript_glob_path ⇒ Object
89 90 91 |
# File 'lib/barista/framework.rb', line 89 def javascript_glob_path @javascript_glob_path ||= File.join(@framework_root, "**", "*.js") end |
#javascripts ⇒ Object
81 82 83 |
# File 'lib/barista/framework.rb', line 81 def javascripts Dir[javascript_glob_path] end |
#output_path_for(file, format = 'js') ⇒ Object
128 129 130 131 132 |
# File 'lib/barista/framework.rb', line 128 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
116 117 118 |
# File 'lib/barista/framework.rb', line 116 def output_root @output_root || Barista.output_root end |
#output_root=(value) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/barista/framework.rb', line 120 def output_root=(value) if value.nil? @output_root = nil else @output_root = Pathname(value.to_s) end end |
#short_name(script) ⇒ Object
93 94 95 96 |
# File 'lib/barista/framework.rb', line 93 def short_name(script) short_name = remove_prefix script, @framework_root File.join(*[@output_prefix, short_name].compact) end |