Sha256: 19493ba48312d73bb11ffa4234ec0ac68f628c9c6eae6d31501b166af6ade373

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'rainpress'

module Sinatra
  module Bundles
    # Bundle for stylesheets
    class StylesheetBundle < Bundle
      # Generate the HTML tag for the stylesheet
      #
      # @param [String] name The name of a bundle
      # @return [String] The HTML that can be inserted into the doc
      def to_html(name, media = :all)
        media = media.join(', ') if media.is_a? Array
        prefix = "/#{@app.stylesheets}/bundles"
        href = @app.stamp_bundles ? "#{prefix}/#{name}/#{stamp}.css" : "#{prefix}/#{name}.css"
        "<link type='text/css' href='#{href}' rel='stylesheet' media='#{media}' />"
      end

    protected

      # The root of these bundles, for path purposes
      def root
        File.join(@app.public, @app.stylesheets)
      end

      # Compress CSS
      #
      # @param [String] css The CSS to compress
      # @return [String] Compressed CSS
      def compress(css)
        Rainpress.compress(css)
      end

      # Get the path of the file on disk
      #
      # @param [String] filename The name of sheet,
      #   assumed to be in the public directory, under 'stylesheets'
      # @return [String] The full path to the file
      def path(filename)
        File.join(root, "#{filename}.css")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinatra-bundles-0.3.0 lib/sinatra/bundles/stylesheet_bundle.rb