Class: Embork::Borkfile::DSL

Inherits:
Object
  • Object
show all
Includes:
Attributes
Defined in:
lib/embork/borkfile.rb

Constant Summary collapse

SUPPORTED_FRAMEWORKS =
%w(bootstrap compass)
SUPPORTED_COMPRESSORS =
%w(closure_compiler uglify)

Instance Attribute Summary

Attributes included from Attributes

#asset_paths, #backend, #compressor, #es6_transform, #frameworks, #helpers, #html, #phrender_index_file, #phrender_javascript_paths, #phrender_raw_javascript, #project_root, #sprockets_engines, #sprockets_postprocessors, #sprockets_preprocessors

Instance Method Summary collapse

Methods included from Attributes

#es6_namespace, #keep_old_versions

Constructor Details

#initialize(environment, logger) ⇒ DSL

Returns a new instance of DSL.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/embork/borkfile.rb', line 42

def initialize(environment, logger)
  Embork.env = @environment = environment.to_sym
  @asset_paths = []
  @helpers = []
  @sprockets_postprocessors = []
  @sprockets_preprocessors = []
  @sprockets_engines = []
  @project_root = nil
  @html = []
  @backend = :static_index
  @keep_old_versions = 5
  @es6_namespace = nil
  @frameworks = []
  @logger = logger
  @compressor = nil
  @es6_transform = nil
  @phrender_javascript_paths = []
  @phrender_raw_javascript = []
  @phrender_index_file = nil
end

Instance Method Details

#add_sprockets_helpers(&block) ⇒ Object



90
91
92
# File 'lib/embork/borkfile.rb', line 90

def add_sprockets_helpers(&block)
  helpers.push block
end

#append_asset_path(path) ⇒ Object



86
87
88
# File 'lib/embork/borkfile.rb', line 86

def append_asset_path(path)
  @asset_paths.push path
end

#compile_html(files) ⇒ Object



120
121
122
123
# File 'lib/embork/borkfile.rb', line 120

def compile_html(files)
  files = [ files ] unless files.kind_of? Array
  @html.concat files
end

#compress_with(compressor) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/embork/borkfile.rb', line 125

def compress_with(compressor)
  if compressor.class == Symbol && SUPPORTED_COMPRESSORS.include?(compressor.to_s)
    @compressor = compressor
  elsif compressor.class != String
    @compressor = compressor
  else
    @logger.critical 'Compressor "%s" is not currently supported by embork.' % compressor.to_s
    @logger.unknown ''
    exit 1
  end
end

#configure(environment, &block) ⇒ Object



110
111
112
113
114
# File 'lib/embork/borkfile.rb', line 110

def configure(environment, &block)
  if environment == @environment
    self.instance_exec &block
  end
end

#get_bindingObject



116
117
118
# File 'lib/embork/borkfile.rb', line 116

def get_binding
  binding
end

#phrender_add_javascript(code) ⇒ Object



106
107
108
# File 'lib/embork/borkfile.rb', line 106

def phrender_add_javascript(code)
  @phrender_raw_javascript.push code
end

#phrender_add_javascript_file(path) ⇒ Object



102
103
104
# File 'lib/embork/borkfile.rb', line 102

def phrender_add_javascript_file(path)
  @phrender_javascript_paths.push path
end

#register_engine(extension, klass) ⇒ Object



82
83
84
# File 'lib/embork/borkfile.rb', line 82

def register_engine(extension, klass)
  @sprockets_engines.push({ :extension => extension, :klass => klass })
end

#register_postprocessor(mime_type, klass) ⇒ Object



74
75
76
# File 'lib/embork/borkfile.rb', line 74

def register_postprocessor(mime_type, klass)
  @sprockets_postprocessors.push({ :mime_type => mime_type, :klass => klass })
end

#register_preprocessor(mime_type, klass) ⇒ Object



78
79
80
# File 'lib/embork/borkfile.rb', line 78

def register_preprocessor(mime_type, klass)
  @sprockets_preprocessors.push({ :mime_type => mime_type, :klass => klass })
end

#set_backend(app) ⇒ Object



98
99
100
# File 'lib/embork/borkfile.rb', line 98

def set_backend(app)
  @backend = app
end

#set_project_root(path) ⇒ Object



94
95
96
# File 'lib/embork/borkfile.rb', line 94

def set_project_root(path)
  @project_root = path
end

#transform_es6_module_names(transform_proc) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/embork/borkfile.rb', line 137

def transform_es6_module_names(transform_proc)
  if transform_proc.respond_to?(:call) || transform_proc.nil?
    @es6_transform = transform_proc
  else
    @logger.critical 'ES6 Module transform must respond to #call'
    exit 1
  end
end

#use_framework(framework) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/embork/borkfile.rb', line 63

def use_framework(framework)
  framework = framework.to_s
  if SUPPORTED_FRAMEWORKS.include? framework
    @frameworks.push framework
  else
    @logger.critical 'Framework "%s" is not currently supported by embork.' % framework
    @logger.unknown ''
    exit 1
  end
end