Skip to content
Browse files

now supports AJAX

  • Loading branch information...
1 parent 7e9c0f2 commit 2e4e4720e3f4c7208f3cdf3da5a158f806a6911c @pgte committed
View
4 README.markdown
@@ -11,4 +11,6 @@ Keep your CSS close to their respective templates. styled_objects will compile t
* [Why do I need styled_objects?](http://wiki.github.com/pgte/styled_objects#why)
* [Installing](http://wiki.github.com/pgte/styled_objects/installing)
* [Getting Started](http://wiki.github.com/pgte/styled_objects/getting-started)
-* [Frequent questions](http://wiki.github.com/pgte/styled_objects/frequent-questions)
+* [Frequent questions](http://wiki.github.com/pgte/styled_objects/frequent-questions)
+* [To do](http://wiki.github.com/pgte/styled_objects/to-do)
+* [Benchmarks](http://wiki.github.com/pgte/styled_objects/benchmarks)
View
4 init.rb
@@ -11,6 +11,8 @@
require 'styled_objects/class_name_builder'
require 'styled_objects/html/decorator'
require 'styled_objects/helpers/stylesheet_link_tag'
+require 'styled_objects/helpers/include'
ActionView::Base.class_eval {include StyledObjects::ActionView::Base}
ActionView::Base.class_eval {include StyledObjects::HTML::Decorator}
-ActionView::Base.class_eval {include StyledObjects::Helpers::StylesheetLinkTag}
+ActionView::Base.class_eval {include StyledObjects::Helpers::StylesheetLinkTag}
+ActionView::Base.class_eval {include StyledObjects::Helpers::Include}
View
12 lib/styled_objects/actionview.rb
@@ -12,17 +12,21 @@ def self.included(base)
alias_method_chain :render, :styled_object unless base.respond_to? :render_with_styled_object
end
end
+
+ def partials_collector
+ @partials_collector || @partials_collector = ::StyledObjects::PartialsCollector.new(view_paths)
+ end
def render_with_styled_object(options = {}, local_assigns = {}, &block)
#render_without_styled_object (options, local_assigns, &block)
# RAILS_DEFAULT_LOGGER.debug("render_with_styled_object with file: #{options[:file].path_without_format_and_extension if options[:file]} and partial #{options[:partial]}")
# RAILS_DEFAULT_LOGGER.debug caller
- @partials_collector ||= ::StyledObjects::PartialsCollector.new(view_paths)
- decorated = template_format == :html && ((options[:file].path_without_format_and_extension unless options[:file].nil?) || options[:partial])
+ #RAILS_DEFAULT_LOGGER.debug "SO: #{template_format}"
+ decorated = [:html, :js].include?(template_format) && ((options[:file].path_without_format_and_extension unless options[:file].nil?) || options[:partial])
#RAILS_DEFAULT_LOGGER.debug "decorated: #{decorated}"
- if decorated && @partials_collector << (partial_full_path = _so_pick_partial_template_path(decorated, options[:file].nil?))
+ if decorated && partials_collector << (partial_full_path = _so_pick_partial_template_path(decorated, options[:file].nil?))
so_decorate partial_full_path do
render_without_styled_object(options, local_assigns, &block)
end
@@ -35,7 +39,7 @@ def render_with_styled_object(options = {}, local_assigns = {}, &block)
protected
def styled_objects_partial_css_paths
- (@partials_collector.partials if @partials_collector) || []
+ (partials_collector.stylesheets if partials_collector) || []
end
View
2 lib/styled_objects/helpers/stylesheet_link_tag.rb
@@ -8,7 +8,7 @@ def self.included(base)
module InstanceMethods
def so_stylesheet_link_tag
- return "<link href=\"#{styledobject_path styled_objects_partial_css_paths.collect {|path| URI.encode(path.gsub(/:|\.css/, ''))}.join(':')}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
+ return "<link href=\"#{styledobject_path styled_objects_partial_css_paths.collect {|path| URI.encode(path.gsub(/:|\.css/, ''))}.join(':')}#{"?#{ENV['RAILS_ASSET_ID']}" if ENV['RAILS_ASSET_ID'] }\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
end
end
View
25 lib/styled_objects/partials_collector.rb
@@ -2,17 +2,21 @@ module StyledObjects
class PartialsCollector
def initialize(view_paths)
- @partials = {}
+ @stylesheets = {}
+ @visited_partials = {}
@view_paths = view_paths
end
def partial_visited(partial)
- style_file = _find_style_file(partial)
- if style_file
- @partials[style_file] = true
- else
- nil
- end
+# unless @visited_partials[partial]
+# @visited_partials[partial] = true
+ style_file = _find_style_file(partial)
+ if style_file
+ @stylesheets[style_file] = true
+ else
+ nil
+ end
+# end
end
@@ -20,8 +24,8 @@ def << (partial)
partial_visited(partial)
end
- def partials
- @partials.keys
+ def stylesheets
+ @stylesheets.keys
end
private
@@ -32,7 +36,8 @@ def _find_style_file(partial)
@view_paths.each do |view_path|
try_path = File.join view_path, style_file
return style_file if File.file? try_path
- end
+ end
+ #raise "SO: did not find style file for #{partial}"
nil
end

0 comments on commit 2e4e472

Please sign in to comment.
Something went wrong with that request. Please try again.