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.



51
52
53
# File 'lib/roda/plugins/assets.rb', line 51

def assets_opts
  opts[:assets]
end

#assets_unique_id(type) ⇒ Object

Generates a unique id, this is used to keep concat/compiled files from caching in the browser when they are generated



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/roda/plugins/assets.rb', line 57

def assets_unique_id(type)
  if unique_id = instance_variable_get("@#{type}")
    unique_id
  else
    path    = "#{assets_opts[:compiled_path]}/#{assets_opts[:"#{type}_folder"]}"
    file    = "#{path}/#{assets_opts[:compiled_name]}.#{type}"
    content = File.exist?(file) ? File.read(file) : ''

    instance_variable_set("@#{type}", Digest::SHA1.hexdigest(content))
  end
end

#compile_assets(concat_only = false) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/roda/plugins/assets.rb', line 69

def compile_assets(concat_only = false)
  assets_opts[:concat_only] = concat_only

  %w(css js).each do |type|
    files = assets_opts[type.to_sym]

    if files.is_a? Array
      compile_process_files files, type, type
    else
      files.each do |folder, f|
        compile_process_files f, type, folder
      end
    end
  end
end

#inherited(subclass) ⇒ Object

Copy the assets options into the subclass, duping them as necessary to prevent changes in the subclass affecting the parent class.



44
45
46
47
48
# File 'lib/roda/plugins/assets.rb', line 44

def inherited(subclass)
  super
  opts         = subclass.opts[:assets] = assets_opts.dup
  opts[:cache] = thread_safe_cache if opts[:cache]
end