Sha256: 4a82c0fcc89fe696209dc4fd4ee1dbdf616598d838d3226e932b36c730a9a4d2

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

module BootstrapRailsEngine
  module ActionViewExtensions
    OFFLINE = (::Rails.env.development? or ::Rails.env.test?)

    CDNS = {
      :bootstrap_js => {
        :default => "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"
      },
      :bootstrap_css => {
        :default => "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css"
      },
    }

    def bootstrap_javascript_url(name, options = {})
      return CDNS[:bootstrap_js][name]
    end

    def bootstrap_stylesheet_url(name, options = {})
      return CDNS[:bootstrap_css][name]
    end

    # to be used with bootstrap-rails-engine gem
    def bootstrap_javascript_include_tag(name, options = {})
      bootstrap_j = 'bootstrap/bootstrap'
      bootstrap_j = bootstrap_j + '.min' if options[:compressed]

      if OFFLINE and !options[:force]
        return javascript_include_tag(bootstrap_j)
      else
        # Bootstrap do not offer way to check existing
        [ javascript_include_tag(bootstrap_javascript_url(name, options)),
          javascript_tag("typeof $().carousel == 'function' || document.write(unescape('#{javascript_include_tag(bootstrap_j).gsub('<','%3C')}'))")
        ].join("\n").html_safe
      end
    end

    def bootstrap_stylesheet_include_tag(name, options = {})
      if OFFLINE and !options[:force]
        return stylesheet_link_tag('bootstrap/bootstrap')
      else
        # Bootstrap do not offer way to check existing
        [ stylesheet_link_tag(bootstrap_stylesheet_url(name, options)),
        ].join("\n").html_safe
      end
    end
  end

  class Engine < ::Rails::Engine
    initializer 'bootstrap-rails-engine.action_view' do |app|
      ActiveSupport.on_load(:action_view) do
        include BootstrapRailsEngine::ActionViewExtensions
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bootstrap-rails-engine-1.3.0.1 lib/bootstrap-rails-engine.rb