Sha256: 618078cda4f6fb8f9525e17b4174c2381c8a11c550d7ad800f15cb9cc0ab74d7

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

module Netzke
  module Stylesheets
    extend ActiveSupport::Concern
  
    included do
      class_attribute :css_included_files
      self.css_included_files = []
    end
      
    module ClassMethods
      # Returns all extra CSS code (as string) required by this component's class
      def css_included
        # Prevent re-including code that was already included by the parent
        # (thus, only include those JS files when include_js was defined in the current class, not in its ancestors)
        ((singleton_methods(false).map(&:to_sym).include?(:include_css) ? include_css : [] ) + css_included_files).inject(""){ |r, path| r + File.new(path).read + "\n"}
      end

      # All CSS code needed for this class including the one from the ancestor component
      def css_code(cached = [])
        res = ""

        # include the base-class javascript if doing JS inheritance
        res << superclass.css_code << "\n" if extends_netzke_component? && !cached.include?(superclass.short_component_class_name)

        res << css_included << "\n"

        res
      end

      # Definition of CSS files which will be dynamically loaded together with this component
      # e.g. 
      # css_include "#{File.dirname(__FILE__)}/themis_navigation/static.css"
      # or
      # css_include "#{File.dirname(__FILE__)}/themis_navigation/one.css","#{File.dirname(__FILE__)}/themis_navigation/two.css"
      #  This is alternative to defining self.include_css
      def css_include(*args)
        self.css_included_files += args
      end
      
    end
    
    module InstanceMethods
      def css_missing_code(cached = [])
        code = dependency_classes.inject("") do |r,k| 
          cached.include?(k) ? r : r + constantize_class_name(k).css_code(cached)
        end
        code.blank? ? nil : code
      end
      
    end    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
netzke-core-0.6.2 lib/netzke/stylesheets.rb
netzke-core-0.6.1 lib/netzke/stylesheets.rb
netzke-core-0.6.0 lib/netzke/stylesheets.rb