Sha256: 355e7ddc87e6d4e756c6030b29b3517b22596c21f5c0ec94cae9357919580d51

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Guilded
  class Guilder

    attr_reader :components,
                :data

    def initialize
      @components = []
      @data       = Guilded::Data.new
    end

    def add( name, options={} )
      components << Guilded::Component.new( name, options )
    end

    def add_data( new_data )
      data.add new_data
    end

    def javascript_initializer
      code = "<script type=\"text/javascript\">\n//<![CDATA[\n"
      code << data.to_javascript
      if javascript_from_components?
        code << "var initGuilded = function(){"
        components.each { |component| code << component.javascript_initializer }
        code << "};"
        code << "jQuery('document').ready(initGuilded);"
      end
      code << "jQuery('body').trigger('guildedInitialized');"
      code << "\n//]]>\n</script>"
      code
    end

    def component?( name )
      components.any? { |component| component.name == name }
    end

    def javascript?
     javascript_from_components? || javascript_from_data?
    end

    def javascript_from_components?
      components.any? { |component| component.javascript? }
    end

    def javascript_from_data?
      !data.empty?
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
guilded-2.0.0 lib/guilded/guilder.rb
guilded-2.0.0.pre lib/guilded/guilder.rb