Sha256: 911075c17c94099092ee8bb392a652132cc7aeec9f3bee96b26f66f2ff6538b5

Contents?: true

Size: 841 Bytes

Versions: 5

Compression:

Stored size: 841 Bytes

Contents

module Linner
  class Asset

    attr_accessor :path, :content

    def initialize(path)
      @path = path
      @content ||= begin
        File.exist?(path) ? Tilt.new(path, :default_encoding => "UTF-8").render : ""
      rescue RuntimeError
        File.read(path)
      end
    end

    def wrap
      Wrapper.wrap(logical_path.chomp(File.extname logical_path), @content)
    end

    def wrappable?
      !!(@path.include? Linner.environment.app_folder and Template.template_for_script?(@path))
    end

    def write
      FileUtils.mkdir_p File.dirname(@path)
      File.open @path, "w" do |file|
        file.write @content
      end
    end

    def compress
      @content = Compressor.compress(self)
    end

    def logical_path
      @logical_path ||= @path.gsub(/#{Linner.environment.app_folder}\/\w*\//, "")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
linner-0.2.0 lib/linner/asset.rb
linner-0.1.5 lib/linner/asset.rb
linner-0.1.4 lib/linner/asset.rb
linner-0.1.3 lib/linner/asset.rb
linner-0.1.2 lib/linner/asset.rb