Skip to content

Commit

Permalink
Release 1.0.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Harrelson committed Jan 21, 2010
1 parent 90158d8 commit ccdca9a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 59 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
= 1.0.5 2010-01-21

* Gave css inclusion a :position option allowing for positioning before or after the component(s) css.


= 1.0.4 2010-01-04

* Fixed a bug with a file include to make guilded work with the bundler gem.
Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -119,7 +119,7 @@ have decided to include support for it in Guilded as of release 0.3.0.

Add to environment file:

config.gem "guilded", :version => '1.0.0', :source => 'http://gemcutter.org'
config.gem "guilded", :version => '1.0.5', :source => 'http://gemcutter.org'

Run:

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.0.4
1.0.5
4 changes: 2 additions & 2 deletions guilded.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{guilded}
s.version = "1.0.4"
s.version = "1.0.5"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["C. Jason Harrelson (midas)"]
s.date = %q{2010-01-04}
s.date = %q{2010-01-21}
s.description = %q{Guilded intends to provide a toolset for creating and consuming reusable web components. Currently, this problem domain is filled with JavaScript frameworks. These frameworks are wonderful and work very well. However, they do not degrade gracefully and are not accessible (in most cases). Guilded seeks to provide the same level of "componentization" and ease of use without sacrificing degradability and accessibility. Guilded will achieve these goals by applying each technology at our disposal (HTML, CSS and JavaScript) to do as it was intended.}
s.email = %q{jason@lookforwardenterprises.com}
s.extra_rdoc_files = [
Expand Down
2 changes: 1 addition & 1 deletion lib/guilded.rb
Expand Up @@ -73,7 +73,7 @@
# <%= g_load_alerter :skin => 'blueish', :id => 'load_alerter' %>
#
module Guilded
VERSION = '1.0.4'
VERSION = '1.0.5'
end

ActionView::Base.send( :include, Guilded::Rails::ViewHelpers ) if defined?( ActionView )
Expand Down
74 changes: 38 additions & 36 deletions lib/guilded/guilder.rb
Expand Up @@ -35,11 +35,12 @@ def initialize #:nodoc:
end
configure_guilded
@initialized_at = Time.now
@g_elements = Hash.new
@g_data_elements = Hash.new
@combined_js_srcs = Array.new
@combined_css_srcs = Array.new
@assets_combined = false
@g_elements = {}
@g_data_elements = {}
@combined_js_srcs = []
@combined_css_srcs = []
@css_temp_hold = { :pre => [], :post => [], :components => [], :reset => [] }
@valid_css_positions = @css_temp_hold.keys
# Make sure that the css reset file is first so that other files can override the reset,
# unless the user specified no reset to be included.
init_sources
Expand Down Expand Up @@ -71,6 +72,10 @@ def add_data( name, data )
def add_js_sources( *sources )
resolve_js_libs( *sources )
end

def add_css_source( src, position=:post )
@css_temp_hold[position.to_sym] << src unless @css_temp_hold[position.to_sym].include?( src )
end

def count #:nodoc:
@g_elements.size
Expand Down Expand Up @@ -103,14 +108,16 @@ def include_component?( type )
# The collection of JavaScript assets for the current Guilded component set.
#
def combined_js_srcs
#generate_asset_lists unless @assets_combined
@combined_js_srcs
end

# The collection of CSS assets for the current Guilded component set.
#
def combined_css_srcs
#generate_asset_lists unless @assets_combined
@css_temp_hold[:reset].each { |src| @combined_css_srcs << src }
@css_temp_hold[:pre].each { |src| @combined_css_srcs << src }
@css_temp_hold[:components].each { |src| @combined_css_srcs << src }
@css_temp_hold[:post].each { |src| @combined_css_srcs << src }
@combined_css_srcs
end

Expand All @@ -120,7 +127,8 @@ def reset!
@combined_css_srcs.clear
@combined_js_srcs.clear
@g_elements.clear
@assets_combined = false
@css_temp_hold = { :pre => [], :post => [], :components => [], :reset => [] }
@valid_css_positions = @css_temp_hold.keys
init_sources
@default_css_count = @combined_css_srcs.size
@default_js_count = @combined_js_srcs.size
Expand All @@ -139,7 +147,7 @@ def inject_js( *sources )
#
def apply #:nodoc:
to_init = ""
generate_asset_lists unless @assets_combined
generate_asset_lists #unless @assets_combined
@combined_css_srcs.each { |css| to_init << "<link href=\"/stylesheets/#{css}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />" }
@combined_js_srcs.each { |js| to_init << "<script type=\"text/javascript\" src=\"/javascripts/#{js}\"></script>" }
to_init << generate_javascript_init
Expand Down Expand Up @@ -174,26 +182,37 @@ def js_cache_name
# and shorter string.
#
def css_cache_name
generate_css_cache_name( @combined_css_srcs )
name = generate_css_cache_name( @combined_css_srcs )
name
end

def generate_js_cache_name( sources ) #:nodoc:
generate_asset_lists unless @assets_combined
#return"#{controller.class.to_s.underscore}_#{controller.action_name}" if development?
sorted_srcs = sources.sort
stripped_srcs = sorted_srcs.map { |src| src.gsub( /.js/, '' ).gsub( /\//, '_') }
joined = stripped_srcs.join( "+" )
"#{Digest::MD5.hexdigest( joined )}"
end

def generate_css_cache_name( sources ) #:nodoc:
generate_asset_lists unless @assets_combined
#return "#{controller.class.to_s.underscore}_#{controller.action_name}" if development?
sorted_srcs = sources.sort
stripped_srcs = sorted_srcs.map { |src| src.gsub( /.css/, '' ).gsub( /\//, '_') }
joined = stripped_srcs.join( "+" )
"#{Digest::MD5.hexdigest( joined )}"
end

# Combines all JavaScript and CSS files into lists to include based on what Guilded components are on
# the current page.
#
def generate_asset_lists #:nodoc:
@g_elements.each_value do |defi|
#TODO get stylesheet (skin) stuff using rails caching
combine_css_sources( defi.kind, defi.options[:skin], defi.styles ) unless defi.exclude_css?

# Combine all JavaScript sources so that the caching option can be used on
# the javascript_incldue_tag helper.
combine_js_sources( defi.kind, defi.libs ) unless defi.exclude_js?
end
end

protected

Expand All @@ -209,7 +228,6 @@ def configure_guilded #:nodoc:
@css_path = @config[:css_path]
@css_folder = @config[:css_folder]
@reset_css = @config[:reset_css]
#@do_reset_css = @config[:do_reset_css]
@env = @config[:environment]
@env ||= :production
@js_path.freeze
Expand All @@ -224,33 +242,17 @@ def configure_guilded #:nodoc:
@guilded_js.freeze
@css_folder.freeze
@reset_css.freeze
#@do_reset_css.freeze
@env.freeze
end

# Adds the Guilded reset CSS file and the guilded.js and jQuery files to the respective sources
# collections.
#
def init_sources #:nodoc:
@combined_css_srcs << "#{@reset_css}" unless @reset_css.nil? || @reset_css.empty?
@css_temp_hold[:reset] << "#{@reset_css}" unless @reset_css.nil? || @reset_css.empty?
resolve_js_libs( "#{@jquery_js}", "#{@jquery_folder}#{@url_js}", "#{@js_folder}#{@guilded_js}" )
end

# Combines all JavaScript and CSS files into lists to include based on what Guilded components are on
# the current page.
#
def generate_asset_lists #:nodoc:
@assets_combined = true
@g_elements.each_value do |defi|
#TODO get stylesheet (skin) stuff using rails caching
combine_css_sources( defi.kind, defi.options[:skin], defi.styles ) unless defi.exclude_css?

# Combine all JavaScript sources so that the caching option can be used on
# the javascript_incldue_tag helper.
combine_js_sources( defi.kind, defi.libs ) unless defi.exclude_js?
end
end

# Helper method that takes the libs and component specific js files and puts them
# into one array so that the javascript_include_tag can correctly cache them. Automatically
# ignores files that have already been inlcuded.
Expand Down Expand Up @@ -323,16 +325,16 @@ def add_guilded_js_path( source ) #:nodoc:
def combine_css_sources( component, skin, styles=[] ) #:nodoc:
# Get all of this components defined external styles
styles.each do |style|
@combined_css_srcs.push( style ) unless @combined_css_srcs.include?( style )
@css_temp_hold[:components].push( style ) unless @css_temp_hold[:components].include?( style )
end

#Get the default or guilded skin styles for this component
comp_src = add_guilded_css_path( component, skin )
@combined_css_srcs.push( comp_src ) unless @combined_css_srcs.include?( comp_src ) || comp_src.empty?
@css_temp_hold[:components].push( comp_src ) unless @css_temp_hold[:components].include?( comp_src ) || comp_src.empty?
user_src = add_guilded_css_path( component, "user" )
@combined_css_srcs.push( user_src ) unless @combined_css_srcs.include?( user_src ) || user_src.empty?
@css_temp_hold[:components].push( user_src ) unless @css_temp_hold[:components].include?( user_src ) || user_src.empty?
skin_user_src = add_guilded_css_path( component, "#{skin || 'default'}_user" )
@combined_css_srcs.push( skin_user_src ) unless @combined_css_srcs.include?( skin_user_src ) || skin_user_src.empty?
@css_temp_hold[:components].push( skin_user_src ) unless @css_temp_hold[:components].include?( skin_user_src ) || skin_user_src.empty?
end

def add_guilded_css_path( source, skin ) #:nodoc:
Expand Down
37 changes: 19 additions & 18 deletions lib/guilded/rails/view_helpers.rb
Expand Up @@ -11,9 +11,11 @@ module ViewHelpers
# call to g_apply_behavior will not output anything.
#
def g_apply_behavior
self.output_buffer.sub!( /<!-- guilded.styles -->/, stylesheet_link_tag( Guilded::Guilder.instance.combined_css_srcs, :cache => "cache/#{Guilded::Guilder.instance.css_cache_name}" ) )
html = javascript_include_tag( Guilded::Guilder.instance.combined_js_srcs, :cache => "cache/#{Guilded::Guilder.instance.js_cache_name}" )
html << Guilded::Guilder.instance.generate_javascript_init
g = Guilded::Guilder.instance
g.generate_asset_lists
self.output_buffer.sub!( /<!-- guilded.styles -->/, stylesheet_link_tag( g.combined_css_srcs, :cache => "cache/#{g.css_cache_name}" ) )
html = javascript_include_tag( g.combined_js_srcs, :cache => "cache/#{g.js_cache_name}" )
html << g.generate_javascript_init
html
end

Expand All @@ -24,11 +26,11 @@ def g_apply_style
# Generates the base javascript includes, if they have not alreay been included.
#
# def g_includes
# return "" if @base_included
# @base_included = true
# javascript_include_tag( 'jquery/jquery-1.2.6.min.js' ) +
# "<script type=\"text/javascript\">$j = jQuery.noConflict(); g={};</script>"
# end
# return "" if @base_included
# @base_included = true
# javascript_include_tag( 'jquery/jquery-1.2.6.min.js' ) +
# "<script type=\"text/javascript\">$j = jQuery.noConflict(); g={};</script>"
# end

# Creates a javascript include tag for a Guilded specific file. The only difference
# being that it adds the file to a sources array to be concatenated and included at the
Expand Down Expand Up @@ -66,8 +68,8 @@ def g_javascript_include_tag( *sources )
''
end

# Written to replace the Rails stylesheet_link_tag helper. Although the syntax
# is exactly the same, the method works a little differently.
# Replaces the Rails stylesheet_link_tag helper if you wnat Guilded to manage CSS for you.
# Although the syntax is exactly the same, the method works a little differently.
#
# This helper adds the stylesheet(s) to a collection to be renderred out together
# with all the guilded componenets stylesheets. This allows the stylesheets passed
Expand All @@ -76,16 +78,15 @@ def g_javascript_include_tag( *sources )
# The helper will ensure that these stylesheets are included after Guilded's reset
# stylesheet and before guilded's component's stylesheets so that they can override any
# resets, etc and not override any guilded components styles.

# *options*
# :position The place to position the css. pre for before the component's css or post for after.
# Defaults to post.
#
def g_stylesheet_link_tag( *sources )
options = sources.extract_options!
g = Guilded::Guilder.instance

if options[:ensure_primary]
g.inject_css( *sources )
else
g.combined_css_srcs.push( *sources )
end
options = sources.extract_options! || {}
options[:position] ||= :post
sources.each { |src| Guilded::Guilder.instance.add_css_source( src, options[:position] ) }
''
end

Expand Down

0 comments on commit ccdca9a

Please sign in to comment.