Sha256: b24f6c3058cb6bb84a09d60c7af77b96d23a82ac7c3c088b063f8c1c36c39362

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

module Luca
  class CompiledAsset
    class << self
      attr_accessor :coffeescript_assets,
                    :sass_assets,
                    :scss_assets,
                    :less_assets,
                    :markdown_assets,
                    :asset_stores_setup
    end

    self.asset_stores_setup = false

    def self.setup_asset_stores
      return if self.asset_stores_setup == true
      
      self.coffeescript_assets  = Luca::Collection.new(namespace:"coffeescripts",backend:"file")
      self.sass_assets          = Luca::Collection.new(namespace:"sass_stylesheets",backend:"file")
      self.scss_assets          = Luca::Collection.new(namespace:"scss_stylesheets",backend:"file")
      self.less_assets          = Luca::Collection.new(namespace:"less_stylesheets",backend:"file")
      self.markdown_assets      = Luca::Collection.new(namespace:"markdown_assets",backend:"file")
      self.asset_stores_setup = true
    end

    attr_accessor :type, :asset 

    def initialize type, asset 
      CompiledAsset.setup_asset_stores
      @type = type
      @asset = asset
    end

    def compiler
      @compiler ||= AssetCompiler.new(input: asset['input'], type: type)
    end

    def output
      compiler.output
    end

    def mime_type
      if type == "coffeescript" || type == "haml" || type == "mustache"
        "text/javascript"
      elsif type == "markdown"
        "text/html"
      else
        "text/css"
      end
    end

    def self.find_by_type_and_id type, id
      if ["markdown", "haml","coffeescript","sass","scss","less"].include?(type)
        asset = self.send("#{ type }_assets".to_sym)
        asset = asset && asset.show(:id)
        if !asset.nil?
          new(type, asset)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
luca-0.9.91 lib/luca/compiled_asset.rb
luca-0.9.9 lib/luca/compiled_asset.rb
luca-0.9.899 lib/luca/compiled_asset.rb
luca-0.9.89 lib/luca/compiled_asset.rb