Permalink
Browse files

js & css is included inline to avoid asset installation

They're also built from templates.
  • Loading branch information...
1 parent db3ae3c commit e1f367bf53758affab7679d505e898cf4c3c5249 @lachie lachie committed Aug 14, 2010
Showing with 59 additions and 2 deletions.
  1. +57 −0 lib/whereuat/assets.rb
  2. +2 −2 lib/whereuat/helpers.rb
View
@@ -0,0 +1,57 @@
+require 'mustache'
+
+module Whereuat
+ module Assets
+ class << self
+ def rebuild!
+ Whereuat.assets_path.mkpath
+
+ Whereuat.javascript_file.open('w') {|f| f << Whereuat.javascript}
+ Whereuat.css_file.open('w') {|f| f << Whereuat.css }
+ end
+ end
+
+ autoload :Image , 'whereuat/assets/image'
+ autoload :Context, 'whereuat/assets/context'
+
+ def template_ctx
+ Context.new
+ end
+
+ def javascript
+ Mustache.render(javascript_template_file.read, Context.new)
+ end
+
+ def css
+ Mustache.render(css_template_file.read, Context.new)
+ end
+
+ def dev_root
+ @dev_root ||= gem_root+'dev'
+ end
+
+ def javascript_template_file
+ @javascript_template_file ||= dev_root+'javascripts/whereuat.js.mustache'
+ end
+
+ def css_template_file
+ @css_template_file ||= dev_root+'stylesheets/whereuat.css.mustache'
+ end
+
+ def javascript_file
+ @javascript_file ||= assets_path+'whereuat.js'
+ end
+
+ def css_file
+ @css_file ||= assets_path+'whereuat.css'
+ end
+
+ def inline_javascript
+ javascript_file.exist? ? javascript_file.read : ''
+ end
+
+ def inline_css
+ css_file.exist? ? css_file.read : ''
+ end
+ end
+end
View
@@ -1,8 +1,8 @@
module Whereuat
module Helpers
def whereuat
- wua = "<script type='text/javascript'>var whereuat_stylesheet_url=#{Whereuat.configuration.whereuat_stylesheet_url.to_json};</script>" +
- "<script type='text/javascript' src='#{Whereuat.configuration.whereuat_javascript_url}'></script>"
+ wua = "<style type='text/css'>#{Whereuat.inline_css}</style>" +
+ "<script type='text/javascript'>#{Whereuat.inline_javascript}</script>"
wua.respond_to?(:html_safe) ? wua.html_safe : wua
end

0 comments on commit e1f367b

Please sign in to comment.