class CabezaDeTermo::Assets::Library

The entry point to the assets library defintion and recollection. To define asset bundles, declare the following in your application:

require ‘cabeza-de-termo/assets/library’

module Web

class Application < Hanami::Application
  configure do
          ...
      CabezaDeTermo::Assets::Library.definition do
        # Css
        bundle :'bootstrap-css' do
          include '/vendor/bootstrap/css/bootstrap.min.css'
        end

        # Js
        bundle :jquery do
          include '/vendor/jquery/jquery-1.11.3.min.js'
        end

        bundle :'bootstrap-js' do
          require :jquery
          include '/vendor/bootstrap/js/bootstrap.min.js'
        end
      end
          ...
  end
end

end

To define which assets to include for a view, you must define a class that delegates the assets recollection to the actual view and layout. A example would be something like this:

class RenderingScopeAdaptor

def collect_stylesheets_with(assets_collector)
        @view.collect_stylesheets_with assets_collector
end

def collect_javascripts_with(assets_collector)
        @view.collect_javascripts_with assets_collector
end

end

See the CabezaDeTermo::Assets::HanamiRenderingScope class for a concrete example.

Finally, in you View or Helper object you must define the methods :collect_stylesheets_with(asset_collector) and :collect_javascripts_with(asset_collector).

class MyView

def collect_stylesheets_with(assets_collector)
        assets_collector.require :'bootstrap-css'
        assets_collector.include 'landing-page.css'
end

def collect_javascripts_with(assets_collector)
        assets_collector.require :'bootstrap-js'
        assets_collector.include 'landing-page.js'
end

end

To collect the assets, call this from your template or helper:

<%= CabezaDeTermo::Assets::Library.stylesheets_for rendering_scope %>

Constants

VERSION

Public Class Methods

bundle_named(name) click to toggle source

Answer the bundle named name from the BundlesLibrary. Raise an error if not found

# File lib/cabeza-de-termo/assets/library.rb, line 86
def self.bundle_named(name)
        bundles_library.bundle_named name
end
bundles_library() click to toggle source

Answer the BundlesLibrary singleton

# File lib/cabeza-de-termo/assets/library.rb, line 81
def self.bundles_library
        @bundles_library
end
definition(&block) click to toggle source

Define the bundles on the BundlesLibrary

# File lib/cabeza-de-termo/assets/library.rb, line 91
def self.definition(&block)
        CdT.bind_block_evaluation_to bundles_library, &block
end
javascripts_for(rendering_scope) click to toggle source

Collect the javascripts defined for the rendering scope. This method can be called directly from the template like this:

<%= CabezaDeTermo::Assets::Library.javascripts_for rendering_scope %>

and then you can iterate on the collected javascripts.

# File lib/cabeza-de-termo/assets/library.rb, line 107
def self.javascripts_for(rendering_scope)
        newRenderingScopeAssetsCollector.collect_javascripts_from rendering_scope
end
newRenderingScopeAssetsCollector() click to toggle source

Answer a new instance of the collector of stylesheets of a rendering_scope

# File lib/cabeza-de-termo/assets/library.rb, line 112
def self.newRenderingScopeAssetsCollector
        RenderingScopeAssetsCollector.new
end
stylesheets_for(rendering_scope) click to toggle source

Collect the stylesheets defined for the rendering scope. This method can be called directly from the template like this:

<%= CabezaDeTermo::Assets::Library.stylesheets_for rendering_scope %>

and then you can iterate on the collected stylesheets.

# File lib/cabeza-de-termo/assets/library.rb, line 99
def self.stylesheets_for(rendering_scope)
        newRenderingScopeAssetsCollector.collect_stylesheets_from rendering_scope
end