ratpack 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = ratpack
2
2
 
3
- Common Rails view helpers, rewritten and wrapped up in a gem for use in your Sinatra app.
3
+ A set of view helpers for Sinatra. Inspired by Rails' ActionView helpers.
4
4
 
5
5
  == Installation
6
6
 
@@ -15,6 +15,7 @@ Install the ratpack gem:
15
15
 
16
16
  Drop this line in your app:
17
17
 
18
+ gem 'ratpack'
18
19
  require 'sinatra/ratpack'
19
20
 
20
21
  == Usage
@@ -25,6 +26,7 @@ See auto-generated documentation at {rdoc.info/projects/zeke/ratpack}[http://rdo
25
26
 
26
27
  * Thanks to the Sinatra page on {Writing Extensions}[http://www.sinatrarb.com/extensions.html]
27
28
  * The url_for method was snagged from {http://github.com/emk/sinatra-url-for/}[github.com/emk/sinatra-url-for]
29
+ * Tests modified from {http://github.com/wbzyl/sinatra-static-assets/}[wbzyl/sinatra-static-assets]
28
30
  * Gem built with {http://github.com/technicalpickles/jeweler/}[Jeweler]
29
31
 
30
32
  == Copyright
@@ -5,6 +5,10 @@ module Sinatra
5
5
 
6
6
  # Accepts a single filename or an array of filenames (with or without .js extension)
7
7
  # Assumes javascripts are in public/javascripts
8
+ #
9
+ # javascript_include_tag "jquery.min" # <script charset="utf-8" src="/javascripts/jquery.min.js" type="text/javascript"></script>
10
+ # javascript_include_tag "jquery.min.js" # <script charset="utf-8" src="/javascripts/jquery.min.js" type="text/javascript"></script>
11
+ # javascript_include_tag %w(day night) # <script charset="utf-8" src="/javascripts/day.js" type="text/javascript"></script>\n<script charset="utf-8" src="/javascripts/night.js" type="text/javascript"></script>
8
12
  def javascript_include_tag(string_or_array, *args)
9
13
  files = string_or_array.is_a?(Array) ? string_or_array : [string_or_array]
10
14
  options = {
@@ -22,6 +26,9 @@ module Sinatra
22
26
 
23
27
  # Accepts a single filename or an array of filenames (with or without .css extension)
24
28
  # Assumes stylesheets are in public/stylesheets
29
+ #
30
+ # stylesheet_link_tag "styles", :media => "print" # <link charset="utf-8" href="/stylesheets/styles.css" media="print" rel="stylesheet" type="text/css" />
31
+ # stylesheet_link_tag %w(winter summer) # <link charset="utf-8" href="/stylesheets/winter.css" media="projection" rel="stylesheet" type="text/css" />\n<link charset="utf-8" href="/stylesheets/summer.css" media="projection" rel="stylesheet" type="text/css" />
25
32
  def stylesheet_link_tag(string_or_array, *args)
26
33
  files = string_or_array.is_a?(Array) ? string_or_array : [string_or_array]
27
34
  options = {
@@ -40,12 +47,20 @@ module Sinatra
40
47
  end
41
48
 
42
49
  # Accepts a full URL, an image filename, or a path underneath /public/images/
50
+ #
51
+ # image_tag "pony.png" # <image src="/images/pony.png" />
52
+ # image_tag "http://foo.com/pony.png" # <image src="http://foo.com/pony.png" />
43
53
  def image_tag(src, options={})
54
+ src = "/images/#{src}" unless src.include? "://" # Add images directory to path if not a full URL
44
55
  options[:src] = url_for(src)
45
56
  tag(:img, options)
46
57
  end
47
58
 
48
59
  # Works like link_to, but href is optional. If no href supplied, content is used as href
60
+ #
61
+ # link_to "grub", "/food", :class => "eats" # <a href="/food" class="eats">grub</a>
62
+ # link_to "http://foo.com" # <a href="http://foo.com">http://foo.com</a>
63
+ # link_to "home" # <a href="/home">home</a>
49
64
  def link_to(content,href=nil,options={})
50
65
  href ||= content
51
66
  options.update :href => url_for(href)
@@ -53,26 +68,18 @@ module Sinatra
53
68
  end
54
69
 
55
70
  # Just like Rails' content_tag
71
+ #
72
+ # content_tag :div, "hello", :id => "foo" # <div id="foo">hello</div>
56
73
  def content_tag(name,content,options={})
57
74
  "<#{name} #{options.to_html_attrs}>#{content}</#{name}>"
58
75
  end
59
76
 
60
77
  # Just like Rails' tag
78
+ #
79
+ # tag :br, :class => "foo" # <br class="foo" />
61
80
  def tag(name,options={})
62
81
  "<#{name} #{options.to_html_attrs} />"
63
82
  end
64
-
65
- # Give this helper an array, and get back a string of <li> elements.
66
- # The first item gets a class of first and the last, well.. last.
67
- # This makes it easier to apply CSS styles to lists, be they ordered or unordered.
68
- def convert_to_list_items(items)
69
- items.inject([]) do |all, item|
70
- css = []
71
- css << "first" if items.first == item
72
- css << "last" if items.last == item
73
- all << content_tag(:li, item, :class => css.join(" "))
74
- end.join("\n")
75
- end
76
83
 
77
84
  # Construct a link to +url_fragment+, which should be given relative to
78
85
  # the base of this Sinatra app. The mode should be either
@@ -81,10 +88,10 @@ module Sinatra
81
88
  # include the site name and port number. (The latter is typically
82
89
  # necessary for links in RSS feeds.) Example usage:
83
90
  #
84
- # url_for "/" # Returns "/myapp/"
85
- # url_for "/foo" # Returns "/myapp/foo"
86
- # url_for "/foo", :full # Returns "http://example.com/myapp/foo"
87
- # url_for "http://bar.com" # Returns "http://bar.com"
91
+ # url_for "/" # "/myapp/"
92
+ # url_for "/foo" # "/myapp/foo"
93
+ # url_for "/foo", :full # "http://example.com/myapp/foo"
94
+ # url_for "http://bar.com" # "http://bar.com"
88
95
  def url_for url_fragment, mode=:path_only
89
96
  return url_fragment if url_fragment.include? "://"
90
97
  url_fragment = "/#{url_fragment}" unless url_fragment.starts_with? "/"
data/test/sinatra_app.rb CHANGED
@@ -17,7 +17,7 @@ end
17
17
  get "/image_tag" do
18
18
  content_type "text/plain"
19
19
  <<"EOD"
20
- #{image_tag("/images/foo.jpg", :alt => "[foo image]")}
20
+ #{image_tag("foo.jpg", :alt => "[foo image]")}
21
21
  EOD
22
22
  end
23
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Sikelianos
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-26 00:00:00 -07:00
12
+ date: 2009-10-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency