Sha256: 1bb83ebb48746b4c77ddbb9ffd9bf7f8c6e0ef7d06c23379242feba9aea33449

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Jekyll
  module AssetsPlugin
    class Renderer
      STYLESHEET = '<link rel="stylesheet" href="%s">'
      JAVASCRIPT = '<script src="%s"></script>'
      IMAGE      = '<img src="%s">'

      def initialize(context, logical_path)
        @site = context.registers[:site]
        @path = logical_path.strip
      end

      def render_asset
        @site.assets[@path].to_s
      end

      def render_asset_path
        @site.asset_path @path
      end

      def render_javascript
        @path << ".js" if File.extname(@path).empty?
        render_tag JAVASCRIPT
      end

      def render_stylesheet
        @path << ".css" if File.extname(@path).empty?
        render_tag STYLESHEET
      end

      def render_image
        render_tag IMAGE
      end

      protected

      def render_tag(template)
        asset = @site.assets[@path]
        tags  = (@site.assets_config.debug ? asset.to_a : [asset]).map do |a|
          format template, AssetPath.new(a).to_s
        end

        tags.join "\n"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jekyll-assets-0.8.1 lib/jekyll/assets_plugin/renderer.rb
jekyll-assets-0.8.0 lib/jekyll/assets_plugin/renderer.rb
tgfa-jekyll-assets-0.7.9.2 lib/jekyll/assets_plugin/renderer.rb
tgfa-jekyll-assets-0.7.9.1 lib/jekyll/assets_plugin/renderer.rb
jekyll-assets-0.7.9 lib/jekyll/assets_plugin/renderer.rb
jekyll-assets-0.7.8 lib/jekyll/assets_plugin/renderer.rb