Permalink
Browse files

update the gemspec to 0.2.2, update readme, added new public folders …

…to the generator bump up gem version to 0.2.2
  • Loading branch information...
1 parent 11aa385 commit 49d5e561fed5127bd177e7aed914b725cef3fbb5 @vanntastic committed Mar 25, 2009
View
@@ -65,6 +65,77 @@ It will also generate test skeletons in the test framework of your choosing.
The --tiny option will create no directories. Just an app.rb, a Rakefile, and a config.ru (Rackup file)
+== ERB Helpers:
+
+Miss some of the erb helpers from ActionView? I've included some helpers that can help:
+
+- image
+ Creates an img tag, very similar to rails' image_tag.
+
+ image src, options={}
+
+ EX:
+
+ image 'your_image.jpg', :title => "Your Image"
+ # => <img src='images/your_image.jpg' title='Your Image' />
+
+- link_css
+ Creates a css link tag for a css file in the public/css directory, very similar to rails' stylesheet_link_tag
+
+ link_css srcs, options={}
+
+ EX:
+
+ # link to a single stylesheet
+ link_css 'app'
+ # => <link rel="stylesheet" href="/css/app.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ # link to multiple stylesheets
+ link_css "app, print"
+
+- link_js
+ Creates a script tag for a javascript file in the public/js directory, similar to rails' javascript_include_tag
+
+ link_js srcs, options={}
+
+ EX:
+
+ # link to a single js file
+ link_js 'app'
+ # link to multiple js files
+ link_js 'jquery,app'
+
+- link
+ Creates an anchor tag, similar to rails' link_to
+
+ link content, options={}
+
+ EX:
+
+ # link to google
+ link "Google", "http://google.com"
+
+- tag
+ Creates an opening and closing html tag, similar to rails' content_tag
+
+ tag name, content, options={}
+
+ EX:
+
+ # create a header tag
+ tag :h1, "Shizam", :title => "Shizam"
+ # => <h1 title="Shizam">Shizam</h1>
+
+- single_tag
+ Creates a single closing html tag, like img tags and link tags
+
+ single_tag name, options
+
+ EX:
+
+ # create an img tag
+ single_tag :img, :src => "my_img.jpg"
+ # => <img src="my_img.jpg" />
+
== ACKNOWLEDGEMENTS:
Big props to the Sinatra developers (http://github.com/bmizerany/sinatra/).
@@ -74,10 +145,13 @@ Also, thanks to Dr. Nic (http://github.com/drnic) for the Rubigen and Newgem lib
To use the --vendor option, git must be installed.
To run the app without using the vendor option, the sinatra gem must be installed.
+If you want to use the erb helpers, activesupport must be installed.
== INSTALL:
- sudo gem install sintra-gen
+ sudo gem install sinatra-gen
+ #or to install the ones with erb helpers
+ sudo gem install vanntastic-sinatra-gen -s http://gems.github.com
You can also install directly from github:
@@ -127,6 +127,9 @@ def parse_actions(*action_args)
lib
test
public
+ public/js
+ public/css
+ public/images
views
)
end
@@ -5,6 +5,8 @@ require 'sinatra'
<%- else -%>
require 'sinatra'
<%- end -%>
+require 'activesupport'
+
<%- unless tiny -%>
require File.join(File.dirname(__FILE__), 'lib', '<%= app_name %>')
require File.join(File.dirname(__FILE__), 'lib', 'app_helper')
@@ -1,3 +1,96 @@
module AppHelper
+ helpers do
+
+ # helper for image_tags
+ # EX : image 'logo.jpg'
+ # => <img src="images/logo.jpg" />
+ def image(src,options={})
+ options[:src] = "/images/#{src}"
+ single_tag(:img, options)
+ end
+
+ # css link helper
+ # EX : link_css 'default'
+ # => <link rel="stylesheet" href="/css/default.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ def link_css(srcs,options={})
+ srcs_length = srcs.split(",").length
+ options[:media] ||= "screen"
+ options[:type] ||= "text/css"
+ options[:rel] ||= "stylesheet"
+ content = ""
+ if srcs_length == 1
+ options[:href] = "/css/#{srcs}.css"
+ content = single_tag(:link, options)
+ else
+ srcs.split(",").each do |src|
+ options[:href] = "/css/#{src}.css"
+ content << single_tag(:link, options)
+ content << "\n"
+ end
+ end
+ content
+ end
+
+ # js link helper
+ # EX : link_js 'app'
+ # => <script src="/js/app.js" type="text/javascript" />
+ # EX : link_js "app,jquery"
+ # => <script src="/js/app.js" type="text/javascript" />
+ # => <script src="/js/jquery.js" type="text/javascript" />
+ def link_js(srcs,options={})
+ srcs_length = srcs.split(",").length
+ content = ""
+ if srcs_length == 1
+ content = single_tag(:script, :src => "/js/#{srcs}.js",
+ :type => "text/javascript")
+ else
+ srcs.split(",").each do |src|
+ content << single_tag(:script, :src => "/js/#{src}.js",
+ :type => "text/javascript")
+ content << "\n"
+ end
+ end
+ content
+ end
+
+ # standard anchor links, like rails' link_to
+ # EX : link "google", "http://google.com"
+ # => <a href="http://google.com">google</a>
+ def link(content,href,options={})
+ options.update :href => href
+ tag :a, content, options
+ end
+
+ # standard open and close tags
+ # EX : tag :h1, "shizam", :title => "shizam"
+ # => <h1 title="shizam">shizam</h1>
+ def tag(name,content,options={})
+ with_opts = "<#{name.to_s} #{options.to_html_attrs}>#{content}</#{name}>"
+ no_opts = "<#{name.to_s}>#{content}</#{name}>"
+ options.blank? ? no_opts : with_opts
+ end
+
+ # standard single closing tags
+ # single_tag :img, :src => "images/google.jpg"
+ # => <img src="images/google.jpg" />
+ def single_tag(name,options={})
+ options ||= options.stringify_keys
+ "<#{name.to_s} #{options.to_html_attrs} />"
+ end
+
+ end
+
+end
+
+class Hash
+
+ def to_html_attrs
+ html_attrs = ""
+ self.stringify_keys.each do |key, val|
+ html_attrs << "#{key}='#{val}' "
+ end
+ html_attrs.chop
+ end
+
end
View
@@ -2,5 +2,5 @@
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
module SinatraGen
- VERSION = '0.2.1'
+ VERSION = '0.2.2'
end
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{sinatra-gen}
- s.version = "0.2.1"
+ s.version = "0.2.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Quint","Vann Ek"]

0 comments on commit 49d5e56

Please sign in to comment.