Sha256: 8a484877ba28f14a6881f5f172072490ab8dbfdf59d59622e66000e000f545df

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8

# TODO: javascript "application" => media/javascripts/application.js
# ... but what if I need full path? It should be tested if file exist, of course
# javascript Path.new("design/whatever.js")
require "rango/helpers"

begin
  require "media-path"
rescue LoadError
  raise LoadError, "You have to install media-path gem!"
end

module Rango
  module Helpers
    # stolen from pupu (but it's OK, it's my code)
    # @since 0.0.2
    def javascript(basename)
      path = MediaPath.new(File.join(Rango.media_root, "javascripts", "#{basename}.js"))
      tag :script, src: path.url, type: "text/javascript"
    end

    # @since 0.0.2
    def stylesheet(basename, attrs = Hash.new)
      path = MediaPath.new(File.join(Rango.media_root, "stylesheets", basename))
      default = {href: path.url, media: 'screen', rel: 'stylesheet', type: 'text/css'}
      single_tag :link, default.merge(attrs)
    end

    def image(basename, attrs = Hash.new)
      path = MediaPath.new(File.join(Rango.media_root, "images", basename))
      default = {src: path.url, alt: path.basename}
      single_tag :img, default.merge(attrs)
    end

    # @since 0.0.2
    def javascripts(*names)
      names.map { |name| self.javascript(name) }.join("\n")
    end

    # @since 0.0.2
    def stylesheets(*names)
      names.map { |name| self.stylesheet(name) }.join("\n")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rango-0.2.3 lib/rango/helpers/assets.rb
rango-0.2.1 lib/rango/helpers/assets.rb
rango-0.2.1.pre lib/rango/helpers/assets.rb
rango-0.2 lib/rango/helpers/assets.rb
rango-0.2.pre lib/rango/helpers/assets.rb