Class: Barista::Framework

Inherits:
Object
  • Object
show all
Defined in:
lib/barista/framework.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options, root = nil, output_prefix = nil)
  unless options.is_a?(Hash)
    Barista.deprecate! self, "initialize(name, root = nil, output_prefix = nil)", "Please use the option syntax instead."
    options = {
      :name          => options,
      :root          => root,
      :output_prefix => output_prefix
    }
  end
  # actually setup the framework.
  check_options! options, :name, :root
  @name            = options[:name].to_s
  @output_prefix   = options[:output_prefix]
  @framework_root  = File.expand_path(options[:root].to_s)
  self.output_root = options[:output_root]
end

Instance Attribute Details

#framework_rootObject (readonly)

Returns the value of attribute framework_root


58
59
60
# File 'lib/barista/framework.rb', line 58

def framework_root
  @framework_root
end

#nameObject (readonly)

Returns the value of attribute name


58
59
60
# File 'lib/barista/framework.rb', line 58

def name
  @name
end

#output_prefixObject

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_pathsObject


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_frameworkObject


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_coffeescriptsObject


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_javascriptsObject


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, options = nil)
  if options.is_a?(Hash)
    framework = self.new(options.merge(:name => name))
  else
    framework = self.new(:name => name, :root => options)
  end
  (@all ||= []) << framework
end

Instance Method Details

#coffeescript_glob_pathObject


85
86
87
# File 'lib/barista/framework.rb', line 85

def coffeescript_glob_path
  @coffeescript_glob_path ||= File.join(@framework_root, "**", "*.coffee")
end

#coffeescriptsObject


77
78
79
# File 'lib/barista/framework.rb', line 77

def coffeescripts
  Dir[coffeescript_glob_path]
end

#exposed_coffeescriptsObject


98
99
100
# File 'lib/barista/framework.rb', line 98

def exposed_coffeescripts
  coffeescripts.map { |script| short_name(script) }
end

#exposed_javascriptsObject


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_pathObject


89
90
91
# File 'lib/barista/framework.rb', line 89

def javascript_glob_path
  @javascript_glob_path ||= File.join(@framework_root, "**", "*.js")
end

#javascriptsObject


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_rootObject


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