Class: AssetsPrecompilerService

Inherits:
Object
  • Object
show all
Defined in:
app/services/assets_precompiler_service.rb

Constant Summary collapse

PUBLIC_PRECOMPILED_ASSET_PATH =
File.join('public', 'assets', 'vinsol_spree_theme')
PUBLIC_PRECOMPILED_ASSET_PATH_FOR_PREVIEW =
File.join('public', 'assets', 'preview_vinsol_spree_theme')
THEME_PATH =
File.join('public', 'vinsol_spree_themes')
CURRENT_THEME_PATH =
File.join(THEME_PATH, 'current')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ AssetsPrecompilerService

Returns a new instance of AssetsPrecompilerService.



10
11
12
# File 'app/services/assets_precompiler_service.rb', line 10

def initialize(theme)
  @theme = theme
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'app/services/assets_precompiler_service.rb', line 3

def env
  @env
end

#manifestObject (readonly)

Returns the value of attribute manifest.



3
4
5
# File 'app/services/assets_precompiler_service.rb', line 3

def manifest
  @manifest
end

#themeObject (readonly)

Returns the value of attribute theme.



3
4
5
# File 'app/services/assets_precompiler_service.rb', line 3

def theme
  @theme
end

Instance Method Details

#copy_assetsObject



21
22
23
24
25
26
27
# File 'app/services/assets_precompiler_service.rb', line 21

def copy_assets
  source_path = File.join(CURRENT_THEME_PATH, 'precompiled_assets', '.')

  FileUtils.rm_r(PUBLIC_PRECOMPILED_ASSET_PATH) if File.exists?(PUBLIC_PRECOMPILED_ASSET_PATH)
  FileUtils.mkdir_p(PUBLIC_PRECOMPILED_ASSET_PATH)
  FileUtils.cp_r(source_path, PUBLIC_PRECOMPILED_ASSET_PATH)
end

#copy_preview_assetsObject



29
30
31
32
33
34
35
# File 'app/services/assets_precompiler_service.rb', line 29

def copy_preview_assets
  source_path = File.join(theme_path, 'precompiled_assets', '.')

  FileUtils.rm_r(PUBLIC_PRECOMPILED_ASSET_PATH_FOR_PREVIEW) if File.exists?(PUBLIC_PRECOMPILED_ASSET_PATH_FOR_PREVIEW)
  FileUtils.mkdir_p(PUBLIC_PRECOMPILED_ASSET_PATH_FOR_PREVIEW)
  FileUtils.cp_r(source_path, PUBLIC_PRECOMPILED_ASSET_PATH_FOR_PREVIEW)
end

#minify(options = {}) ⇒ Object



14
15
16
17
18
19
# File 'app/services/assets_precompiler_service.rb', line 14

def minify(options= {})
  options.merge!({ precompile: true }) unless options.key?(:precompile)
  build_environment
  build_manifest
  options[:precompile] ? assets_precompile : manifest
end