Sha256: cb8555c4b4535c6507bcf12795cc6aa8b1cae452515d86df45c8e84b7a6c7464

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'sinatra/base'

gem 'emk-sinatra-url-for'
require 'sinatra/url_for'

module Sinatra
  module StaticAssets

    def image_tag(source, options = {})
      options[:src] = url_for(source)
      tag("img", options)  
    end
    
    def stylesheet_link_tag(*sources)
      # TODO  
    end
    
    def javascript_include_tag(*sources)
      # TODO
    end

    private
    
    def tag(name, options = nil, open = false)
      "<#{name}#{tag_options(options) if options}#{open ? ">" : " />"}"
    end
    
    def tag_options(options)
      unless options.empty?
        attrs = []
        attrs = options.map { |key, value| %(#{key}="#{value}") }
        " #{attrs.sort * ' '}" unless attrs.empty?
      end
    end
    
    # html_.. -> url_for..
    # <link .. /?> ?
    def stylesheet_tag(source, options)
      tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen",
          "href" => html_escape(path_to_stylesheet(source)) }.merge(options), false)
    end
    
    def javascript_src_tag(source, options)
      # append onto tag </script>
    end
    
  end

  helpers StaticAssets
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wbzyl-sinatra-static-assets-0.0.2 lib/sinatra/static_assets.rb