Permalink
Browse files

Javascript and CSS helpers

  • Loading branch information...
1 parent 5b91c07 commit e54edecb0fb63ccc5a803a5819586dafec113712 @peteog committed Dec 15, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 lib/sinatra/simple_assets.rb
@@ -4,6 +4,20 @@ module Sinatra
module SimpleAssets
VERSION = '0.0.1'
+ module Helpers
+ def stylesheet(name)
+ settings.assets.paths_for("#{name}.css").map do |file|
+ "<link rel=\"stylesheet\" href=\"#{url(file)}\">"
+ end.join("\n")
+ end
+
+ def javascript(name)
+ settings.assets.paths_for("#{name}.js").map do |file|
+ "<script src=\"#{url(file)}\"></script>"
+ end.join("\n")
+ end
+ end
+
class Assets
def initialize(app, &block)
@app = app
@@ -15,10 +29,18 @@ def css(name, files)
def js(name, files)
end
+
+ def paths_for(name)
+ []
+ end
end
def assets(&block)
@assets ||= Assets.new(self, &block)
end
+
+ def self.registered(app)
+ app.helpers SimpleAssets::Helpers
+ end
end
end

0 comments on commit e54edec

Please sign in to comment.