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/rake_task.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, RakeTask, 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

.add_preamble(&blk) ⇒ Object



68
69
70
71
72
73
# File 'lib/barista.rb', line 68

def add_preamble(&blk)
  self.add_preamble = true
  if block_given?
    @preamble = blk
  end
end

.app_rootObject



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

def app_root
  @app_root ||= default_for_app_root
end

.app_root=(value) ⇒ Object



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

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

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



209
210
211
212
# File 'lib/barista.rb', line 209

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

.change_output_root!(framework, root) ⇒ Object



214
215
216
217
# File 'lib/barista.rb', line 214

def change_output_root!(framework, root)
  framework = Barista::Framework[framework] unless framework.is_a?(Barista::Framework)
  framework.output_root = root if framework
end

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



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/barista.rb', line 195

def compile_all!(force = false, silence_error = true)
  debug "Compiling all coffeescripts" if Barista.auto_compile?
  Barista.invoke_hook :before_full_compilation
  Framework.exposed_coffeescripts.each do |coffeescript|
    Compiler.autocompile_file coffeescript, force, silence_error
  end
  debug "Copying all javascripts"
  Framework.exposed_javascripts.each do |javascript|
    Compiler.autocompile_file javascript, 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.



191
192
193
# File 'lib/barista.rb', line 191

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



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

def configure
  yield self if block_given?
end

.debug(message) ⇒ Object



227
228
229
# File 'lib/barista.rb', line 227

def debug(message)
  logger.debug "[Barista] #{message}" if logger && verbose?
end

.default_for_add_filterObject



172
173
174
# File 'lib/barista.rb', line 172

def default_for_add_filter
  local_env?
end

.default_for_app_rootObject



151
152
153
154
155
156
157
# File 'lib/barista.rb', line 151

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

.default_for_auto_compileObject



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

def default_for_auto_compile
  true
end

.default_for_embedded_interpreterObject



180
181
182
# File 'lib/barista.rb', line 180

def default_for_embedded_interpreter
  false
end

.default_for_envObject



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

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



176
177
178
# File 'lib/barista.rb', line 176

def default_for_exception_on_error
  true
end

.default_for_loggerObject



159
160
161
162
163
164
165
166
# File 'lib/barista.rb', line 159

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

.default_for_verboseObject



168
169
170
# File 'lib/barista.rb', line 168

def default_for_verbose
  local_env?
end

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



219
220
221
# File 'lib/barista.rb', line 219

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

.envObject



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

def env
  @env ||= default_for_env
end

.env=(value) ⇒ Object



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

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

.has_hook?(name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/barista.rb', line 50

def has_hook?(name)
  hooks.has_hook?(name)
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.



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

def hooks
  @hooks ||= Hooks.new
end

.invoke_hook(name, *args) ⇒ Object



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

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

.library_rootObject



29
30
31
# File 'lib/barista.rb', line 29

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

.local_env?Boolean

Default configuration options

Returns:

  • (Boolean)


142
143
144
# File 'lib/barista.rb', line 142

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

.loggerObject



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

def logger
  @logger ||= default_for_logger
end

.logger=(value) ⇒ Object



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

def logger=(value)
  @logger = value
end

.no_wrap!Object



130
131
132
133
# File 'lib/barista.rb', line 130

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

.no_wrap=(value) ⇒ Object



135
136
137
138
# File 'lib/barista.rb', line 135

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

.no_wrap?Boolean

Returns:

  • (Boolean)


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

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

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



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

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

.output_path_for(file) ⇒ Object



223
224
225
# File 'lib/barista.rb', line 223

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

.output_rootObject



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

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

.output_root=(value) ⇒ Object



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

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

.preambleObject



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

def preamble
  @preamble
end

.rootObject



108
109
110
# File 'lib/barista.rb', line 108

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

.root=(value) ⇒ Object



112
113
114
115
# File 'lib/barista.rb', line 112

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

.setup_defaultsObject



231
232
233
234
# File 'lib/barista.rb', line 231

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