Module: Roda::RodaPlugins::Assets::ClassMethods

Defined in:
lib/roda/plugins/assets.rb

Instance Method Summary collapse

Instance Method Details

#assets_optsObject

Return the assets options for this class.



462
463
464
# File 'lib/roda/plugins/assets.rb', line 462

def assets_opts
  opts[:assets]
end

#compile_assets(type = nil) ⇒ Object

Compile options for the given asset type. If no asset_type is given, compile both the :css and :js asset types. You can specify an array of types (e.g. [:css, :frontend]) to compile assets for the given asset group.



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/roda/plugins/assets.rb', line 470

def compile_assets(type=nil)
  require 'fileutils'

  unless assets_opts[:compiled]
    opts[:assets] = assets_opts.merge(:compiled => _compiled_assets_initial_hash).freeze
  end

  if type == nil
    _compile_assets(:css)
    _compile_assets(:js)
  else
    _compile_assets(type)
  end

  if precompile_file = assets_opts[:precompiled]
    require 'json'
    ::FileUtils.mkdir_p(File.dirname(precompile_file))
    tmp_file = "#{precompile_file}.tmp"
    ::File.open(tmp_file, 'wb'){|f| f.write((opts[:json_serializer] || :to_json.to_proc).call(assets_opts[:compiled]))}
    ::File.rename(tmp_file, precompile_file)
  end

  assets_opts[:compiled]
end