Module: Barista

Extended by:
Extensions
Defined in:
lib/barista.rb,
lib/barista/hooks.rb,
lib/barista/filter.rb,
lib/barista/server.rb,
lib/barista/helpers.rb,
lib/barista/version.rb,
lib/barista/compiler.rb,
lib/barista/framework.rb,
lib/barista/extensions.rb,
lib/barista/haml_filter.rb,
lib/barista/integration.rb,
lib/barista/integration/rails2.rb,
lib/barista/integration/rails3.rb,
lib/barista/integration/sinatra.rb,
lib/generators/barista/install/install_generator.rb

Defined Under Namespace

Modules: Extensions, Generators, HamlFilter, Helpers, Integration, Version Classes: Compiler, Filter, Framework, Hooks, Server

Constant Summary collapse

Error =
Class.new(StandardError)
CompilationError =
Class.new(Error)
CompilerUnavailableError =
Class.new(Error)

Class Method Summary collapse

Methods included from Extensions

included

Class Method Details

.app_rootObject



80
81
82
# File 'lib/barista.rb', line 80

def app_root
  @app_root ||= default_for_app_root
end

.app_root=(value) ⇒ Object



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

def app_root=(value)
  @app_root = value.nil? ? nil : Pathname(value.to_s)
end

.change_output_prefix!(framework, prefix = nil) ⇒ Object



184
185
186
187
# File 'lib/barista.rb', line 184

def change_output_prefix!(framework, prefix = nil)
  framework = Barista::Framework[framework] unless framework.is_a?(Barista::Framework)
  framework.output_prefix = prefix if framework.present?
end

.compile_all!(force = false, silence_error = true) ⇒ Object



174
175
176
177
178
179
180
181
182
# File 'lib/barista.rb', line 174

def compile_all!(force = false, silence_error = true)
  debug "Compiling all coffeescripts"
  Barista.invoke_hook :before_full_compilation
  Framework.exposed_coffeescripts.each do |coffeescript|
    Compiler.autocompile_file coffeescript, force, silence_error
  end
  Barista.invoke_hook :all_compiled
  true
end

.compile_file!(file, force = false, silence_error = false) ⇒ Object

Actual tasks on the barista module.



170
171
172
# File 'lib/barista.rb', line 170

def compile_file!(file, force = false, silence_error = false)
  Compiler.autocompile_file file, force, silence_error
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Barista)

    the object that the method was called on



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

def configure
  yield self if block_given?
end

.debug(message) ⇒ Object



197
198
199
# File 'lib/barista.rb', line 197

def debug(message)
  logger.debug "[Barista] #{message}"
end

.default_for_add_filterObject



152
153
154
# File 'lib/barista.rb', line 152

def default_for_add_filter
  local_env?
end

.default_for_add_preambleObject



156
157
158
# File 'lib/barista.rb', line 156

def default_for_add_preamble
  local_env?
end

.default_for_app_rootObject



131
132
133
134
135
136
137
# File 'lib/barista.rb', line 131

def default_for_app_root
  if defined?(Rails.root)
    Rails.root
  else
    Pathname(Dir.pwd)
  end
end

.default_for_embedded_interpreterObject



164
165
166
# File 'lib/barista.rb', line 164

def default_for_embedded_interpreter
  local_env?
end

.default_for_envObject



126
127
128
129
# File 'lib/barista.rb', line 126

def default_for_env
  return Rails.env.to_s if defined?(Rails.env)
  ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end

.default_for_exception_on_errorObject



160
161
162
# File 'lib/barista.rb', line 160

def default_for_exception_on_error
  true
end

.default_for_loggerObject



139
140
141
142
143
144
145
146
# File 'lib/barista.rb', line 139

def default_for_logger
  if defined?(Rails.logger)
    Rails.logger
  else
    require 'logger'
    Logger.new(STDOUT)
  end
end

.default_for_verboseObject



148
149
150
# File 'lib/barista.rb', line 148

def default_for_verbose
  local_env?
end

.each_framework(include_default = false, &blk) ⇒ Object



189
190
191
# File 'lib/barista.rb', line 189

def each_framework(include_default = false, &blk)
  Framework.all(include_default).each(&blk)
end

.envObject



63
64
65
# File 'lib/barista.rb', line 63

def env
  @env ||= default_for_env
end

.env=(value) ⇒ Object



67
68
69
70
# File 'lib/barista.rb', line 67

def env=(value)
  @env = value.to_s.strip
  @env = nil if @env == ''
end

.hooksObject

Hook methods

Hooks are a generic way to define blocks that are executed at run time. For a full list of hooks, see the readme.



33
34
35
# File 'lib/barista.rb', line 33

def hooks
  @hooks ||= Hooks.new
end

.invoke_hook(name, *args) ⇒ Object



41
42
43
# File 'lib/barista.rb', line 41

def invoke_hook(name, *args)
  hooks.invoke(name, *args)
end

.library_rootObject



24
25
26
# File 'lib/barista.rb', line 24

def library_root
  @library_root ||= Pathname(__FILE__).dirname
end

.local_env?Boolean

Default configuration options

Returns:

  • (Boolean)


122
123
124
# File 'lib/barista.rb', line 122

def local_env?
  %w(test development).include? Barista.env
end

.loggerObject



72
73
74
# File 'lib/barista.rb', line 72

def logger
  @logger ||= default_for_logger
end

.logger=(value) ⇒ Object



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

def logger=(value)
  @logger = value
end

.no_wrap!Object



110
111
112
113
# File 'lib/barista.rb', line 110

def no_wrap!
  deprecate! self, :no_wrap!, 'Please use bare! instead.'
  bare!
end

.no_wrap=(value) ⇒ Object



115
116
117
118
# File 'lib/barista.rb', line 115

def no_wrap=(value)
  deprecate! self, :no_wrap=, 'Please use bare= instead.'
  self.bare = value
end

.no_wrap?Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/barista.rb', line 105

def no_wrap?
  deprecate! self, :no_wrap?, 'Please use bare? instead.'
  bare?
end

.on_hook(name, *args, &blk) ⇒ Object



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

def on_hook(name, *args, &blk)
  hooks.on(name, *args, &blk)
end

.output_path_for(file) ⇒ Object



193
194
195
# File 'lib/barista.rb', line 193

def output_path_for(file)
  output_root.join(file.to_s.gsub(/^\/+/, '')).to_s.gsub(/\.coffee$/, '.js')
end

.output_rootObject



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

def output_root
  @output_root ||= app_root.join("public", "javascripts")
end

.output_root=(value) ⇒ Object



101
102
103
# File 'lib/barista.rb', line 101

def output_root=(value)
  @output_root = value.nil? ? nil : Pathname(value.to_s)
end

.rootObject



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

def root
  @root ||= app_root.join("app", "coffeescripts")
end

.root=(value) ⇒ Object



92
93
94
95
# File 'lib/barista.rb', line 92

def root=(value)
  @root = value.nil? ? nil : Pathname(value.to_s)
  Framework.default_framework = nil
end

.setup_defaultsObject



201
202
203
204
# File 'lib/barista.rb', line 201

def setup_defaults
  Barista::HamlFilter.setup
  Barista::Compiler.setup_default_error_logger
end