Class: Embork::Environment

Inherits:
Object
  • Object
show all
Includes:
Sprockets::Frameworks
Defined in:
lib/embork/environment.rb

Defined Under Namespace

Classes: ErblessCache

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sprockets::Frameworks

#load_bootstrap_framework, #load_compass_framework

Constructor Details

#initialize(borkfile, options = {}) ⇒ Environment

Returns a new instance of Environment.



23
24
25
26
27
28
29
30
31
32
# File 'lib/embork/environment.rb', line 23

def initialize(borkfile, options = {})
  @borkfile = borkfile

  setup_sprockets

  if !@borkfile.es6_namespace.nil?
    Embork::Sprockets::ES6ModuleTranspiler.namespace = @borkfile.es6_namespace
    Embork::Sprockets::EmberHandlebarsCompiler.namespace = @borkfile.es6_namespace
  end
end

Instance Attribute Details

#bundle_versionObject (readonly)

Returns the value of attribute bundle_version.



9
10
11
# File 'lib/embork/environment.rb', line 9

def bundle_version
  @bundle_version
end

#sprockets_environmentObject (readonly)

Returns the value of attribute sprockets_environment.



8
9
10
# File 'lib/embork/environment.rb', line 8

def sprockets_environment
  @sprockets_environment
end

#use_bundled_assetsObject (readonly)

Returns the value of attribute use_bundled_assets.



10
11
12
# File 'lib/embork/environment.rb', line 10

def use_bundled_assets
  @use_bundled_assets
end

Instance Method Details

#setup_compressorObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/embork/environment.rb', line 99

def setup_compressor
  if @borkfile.compressor == :closure_compiler
    @sprockets_environment.register_bundle_processor 'application/javascript',
      Embork::Sprockets::ClosureCompiler
  elsif @borkfile.compressor == :uglify
    @sprockets_environment.js_compressor = :uglify
  elsif @borkfile.compressor
    @sprockets_environment.register_bundle_processor 'application/javascript',
      @borkfile.compressor
  end
end

#setup_enginesObject



86
87
88
89
90
# File 'lib/embork/environment.rb', line 86

def setup_engines
  @borkfile.sprockets_engines.each do |engine|
    @sprockets_environment.register_engine engine[:extension], engine[:klass]
  end
end

#setup_frameworksObject



92
93
94
95
96
97
# File 'lib/embork/environment.rb', line 92

def setup_frameworks
  @borkfile.frameworks.each do |framework|
    method = ('load_%s_framework' % framework).to_sym
    self.send method, @sprockets_environment
  end
end

#setup_helpersObject



67
68
69
70
71
72
73
74
75
# File 'lib/embork/environment.rb', line 67

def setup_helpers
  @borkfile.helpers.each do |helper_proc|
    Embork::Sprockets::Helpers.class_eval &helper_proc
  end
  @sprockets_environment.context_class.class_eval do
    include Embork::Sprockets::Helpers
    extend Embork::Sprockets::Helpers::ClassMethods
  end
end

#setup_pathsObject



61
62
63
64
65
# File 'lib/embork/environment.rb', line 61

def setup_paths
  @borkfile.asset_paths.each do |path|
    @sprockets_environment.append_path path
  end
end

#setup_processorsObject



77
78
79
80
81
82
83
84
# File 'lib/embork/environment.rb', line 77

def setup_processors
  @borkfile.sprockets_postprocessors.each do |processor|
    @sprockets_environment.register_postprocessor processor[:mime_type], processor[:klass]
  end
  @borkfile.sprockets_preprocessors.each do |processor|
    @sprockets_environment.register_preprocessor processor[:mime_type], processor[:klass]
  end
end

#setup_sprocketsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/embork/environment.rb', line 34

def setup_sprockets
  @sprockets_environment = Sprockets::Environment.new @borkfile.project_root
  cache_path = File.join @borkfile.project_root, '.cache'
  @sprockets_environment.cache = ErblessCache.new(cache_path)

  setup_sprockets_defaults

  setup_paths
  setup_helpers
  setup_processors
  setup_engines
  setup_frameworks
  setup_transforms
  setup_compressor if @borkfile.compressor
end

#setup_sprockets_defaultsObject



54
55
56
57
58
59
# File 'lib/embork/environment.rb', line 54

def setup_sprockets_defaults
  @sprockets_environment.register_postprocessor 'application/javascript', Embork::Sprockets::ES6ModuleTranspiler
  @sprockets_environment.register_engine '.hbs', Embork::Sprockets::EmberHandlebarsCompiler
  @sprockets_environment.register_engine '.handlebars', Embork::Sprockets::EmberHandlebarsCompiler
  ::Tilt::CoffeeScriptTemplate.default_bare = true
end

#setup_transformsObject



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

def setup_transforms
  Embork::Sprockets::ES6ModuleTranspiler.transform = @borkfile.es6_transform
end