Sha256: 0dbe21a31176647ea1f97300272927cf5fab7f7ae2ca85944e4d1821f90399c6

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

module Netzke
  module Core
    # This class is responsible of assemblage of stylesheet dependencies. It is passed as block parameter to the +client_styles+ DSL method:
    #
    #     class MyComponent < Netzke::Base
    #       client_styles do |c|
    #         c.require :extra_styles
    #       end
    #     end
    class CssConfig

      attr_accessor :required_files

      def initialize(klass)
        @klass = klass
        @required_files = []
      end

      # Use it to specify extra stylesheet files to be loaded for the component.
      #
      # It may accept one or more symbols or strings.
      #
      # Symbols will be expanded following a convention, e.g.:
      #
      #     class MyComponent < Netzke::Base
      #       client_styles do |c|
      #         c.require :some_styles
      #       end
      #     end
      #
      # This will "require" a stylesheet file +{component_location}/my_component/client/some_styles.css+
      #
      # Strings will be interpreted as full paths to the required JavaScript file:
      #
      #     client_styles do |c|
      #       c.require "#{File.dirname(__FILE__)}/my_component/one.css", "#{File.dirname(__FILE__)}/my_component/two.css"
      #     end
      def require(*args)
        callr = caller.first
        @required_files |= args.map{ |a| a.is_a?(Symbol) ? expand_css_require_path(a, callr) : a }
      end

    private

      def expand_css_require_path(sym, callr)
        %Q(#{callr.split(".rb:").first}/client/#{sym}.css)
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
netzke-core-6.5.0.0 lib/netzke/core/css_config.rb
netzke-core-6.5.0.0.rc2 lib/netzke/core/css_config.rb
netzke-core-6.5.0.0.rc1 lib/netzke/core/css_config.rb
netzke-core-1.0.1.0 lib/netzke/core/css_config.rb
netzke-core-1.0.0.0 lib/netzke/core/css_config.rb
netzke-core-1.0.0.0.pre4 lib/netzke/core/css_config.rb
netzke-core-1.0.0.0.pre3 lib/netzke/core/css_config.rb
netzke-core-1.0.0.0.pre2 lib/netzke/core/css_config.rb
netzke-core-1.0.0.0.pre lib/netzke/core/css_config.rb