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.



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(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)
  @output_root    = options[:output_root] && Pathname(options[:output_root])
end

Instance Attribute Details

#framework_rootObject (readonly)

Returns the value of attribute framework_root.



46
47
48
# File 'lib/barista/framework.rb', line 46

def framework_root
  @framework_root
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/barista/framework.rb', line 46

def name
  @name
end

#output_prefixObject

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_pathsObject



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_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

.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

.register(name, root) ⇒ Object



37
38
39
# File 'lib/barista/framework.rb', line 37

def self.register(name, root)
  (@all ||= []) << self.new(:name => name, :root => root)
end

Instance Method Details

#coffeescript_glob_pathObject



69
70
71
# File 'lib/barista/framework.rb', line 69

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

#coffeescriptsObject



65
66
67
# File 'lib/barista/framework.rb', line 65

def coffeescripts
  Dir[coffeescript_glob_path]
end

#exposed_coffeescriptsObject



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_rootObject



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