### Home Classes Methods

### In Files

- lib/ramaze/helper/xhtml.rb

### Methods

- #css
- #css_for
- #js
- #js_for

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::Helper::XHTML

Provides shortcuts to the link/script tags.

The XHTML helper can be used for generating CSS and Javascript tags. Generating a CSS tag can be done by calling the css() method:

    css 'reset', 'screen', :only => 'ie'

This would result in a stylesheet named "reset.css" being loaded only when the user is using Internet Explorer.

### Constants

LINK_TAG
SCRIPT_TAG

### Public Instance Methods

css(name, media = 'screen', options = {}) click to toggle source

Generate a CSS tag based on the name, media type and a hash containing additional options. For example, if we want to load the stylesheet only when the user is using Internet Explorer we would have to add a key 'only' with a value of 'ie' to the hash.

@param [String] name The name of the CSS file to load. @param [String] media The media type for which the stylesheet should be

    loaded.

@param [Hash] options A hash containing additional options for the

    stylesheet tag.

@example

    # A very basic example.
    css 'reset'

    # Oh shiny, IE only
    css 'reset', 'screen', :only => 'ie'

@return [String] String containing the stylesheet tag.

    # File lib/ramaze/helper/xhtml.rb, line 38
    def css(name, media = 'screen', options = {})
      if media.respond_to?(:keys)
        options = media
        media = 'screen'
      end

      if only = options.delete(:only) and only.to_s == 'ie'
        "<!--[if IE]>#{css(name, media, options)}<![endif]-->"
      else
        if name =~ /^http/
          LINK_TAG % [name, media]
        else
          prefix = options[:prefix] || 'css'
          LINK_TAG % [
            "#{Ramaze.options.prefix.chomp("/")}/#{prefix}/#{name}.css",
            media
          ]
        end
      end
    end

css_for(*args) click to toggle source

The css_for method can be used when you want to load multiple stylesheets and don't want to call the css() method over and over again.

@example

    # This is pretty basic
    css_for 'reset', '960', 'style'

    # Loading multiple stylesheets with custom options
    css_for ['reset', 'print'], ['960', 'print']

@see css() @param [Array] args An array containing either the names of all

    stylesheets to load or a collection of arrays of which each array
    defines the name, media and additional parameters.

@return [String]

    # File lib/ramaze/helper/xhtml.rb, line 77
    def css_for(*args)
      args.map{|arg| css(*arg) }.join("\n")
    end

js(name, options={}) click to toggle source

Generates a Javascript tag that loads an external Javascript file. This tag can't be used for loading inline Javascript files.

@example

    # Simple isn't it?
    js 'jquery'

    # Let's change the directory to "some_other_directory"
    js 'jquery', :prefix => 'some_other_directory'

@param [String] name The name of the Javascript file that should be

    loaded.

@param [Hash] options Hash that can contain a :prefix key that defines

    the directory in which the JS file is located. By default this key is
    set to "js".

@return [String]

    # File lib/ramaze/helper/xhtml.rb, line 99
    def js(name, options={})
      if name =~ /^http/ # consider it external full url
        SCRIPT_TAG % name
      else
        SCRIPT_TAG % "#{Ramaze.options.prefix.chomp("/")}/#{options[:prefix] || 'js'}/#{name}.js"
      end
    end

js_for(*args) click to toggle source

Generate multiple Javascript tags using the js() method.

@example

    # Pretty simple isn't it?
    js_for 'jquery', 'application', 'jquery.gritter'

@param [Array] args Array containing the Javascript files to load. @return [String]

    # File lib/ramaze/helper/xhtml.rb, line 117
    def js_for(*args)
      args.map{|arg| js(*arg) }.join("\n")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.