Skip to content

Commit

Permalink
js & css is included inline to avoid asset installation
Browse files Browse the repository at this point in the history
They're also built from templates.
  • Loading branch information
lachie committed Aug 14, 2010
1 parent db3ae3c commit e1f367b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions lib/whereuat/assets.rb
@@ -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
4 changes: 2 additions & 2 deletions lib/whereuat/helpers.rb
@@ -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
Expand Down

0 comments on commit e1f367b

Please sign in to comment.