markaby 0.2 → 0.3

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.
Files changed (57) hide show
  1. data/README +189 -0
  2. data/Rakefile +15 -0
  3. data/doc/rdoc/classes/Markaby.html +192 -0
  4. data/doc/rdoc/classes/Markaby/ActionControllerHelper.html +145 -0
  5. data/doc/rdoc/classes/Markaby/ActionControllerHelper.src/M000005.html +20 -0
  6. data/doc/rdoc/classes/Markaby/Builder.html +480 -0
  7. data/doc/rdoc/classes/Markaby/Builder.src/M000008.html +44 -0
  8. data/doc/rdoc/classes/Markaby/Builder.src/M000009.html +18 -0
  9. data/doc/rdoc/classes/Markaby/Builder.src/M000010.html +19 -0
  10. data/doc/rdoc/classes/Markaby/Builder.src/M000012.html +24 -0
  11. data/doc/rdoc/classes/Markaby/Builder.src/M000013.html +18 -0
  12. data/doc/rdoc/classes/Markaby/Builder.src/M000014.html +22 -0
  13. data/doc/rdoc/classes/Markaby/Builder.src/M000015.html +38 -0
  14. data/doc/rdoc/classes/Markaby/Builder.src/M000016.html +18 -0
  15. data/doc/rdoc/classes/Markaby/Builder.src/M000017.html +18 -0
  16. data/doc/rdoc/classes/Markaby/Builder.src/M000018.html +21 -0
  17. data/doc/rdoc/classes/Markaby/Builder.src/M000019.html +24 -0
  18. data/doc/rdoc/classes/Markaby/Builder.src/M000021.html +18 -0
  19. data/doc/rdoc/classes/Markaby/CssProxy.html +177 -0
  20. data/doc/rdoc/classes/Markaby/CssProxy.src/M000006.html +19 -0
  21. data/doc/rdoc/classes/Markaby/CssProxy.src/M000007.html +33 -0
  22. data/doc/rdoc/classes/Markaby/Template.html +156 -0
  23. data/doc/rdoc/classes/Markaby/Template.src/M000022.html +18 -0
  24. data/doc/rdoc/classes/Markaby/Template.src/M000023.html +20 -0
  25. data/doc/rdoc/classes/Markaby/View.html +156 -0
  26. data/doc/rdoc/classes/Markaby/View.src/M000024.html +18 -0
  27. data/doc/rdoc/classes/Markaby/View.src/M000025.html +18 -0
  28. data/doc/rdoc/classes/Object.html +199 -0
  29. data/doc/rdoc/classes/Object.src/M000001.html +16 -0
  30. data/doc/rdoc/classes/Object.src/M000002.html +16 -0
  31. data/doc/rdoc/classes/Object.src/M000003.html +18 -0
  32. data/doc/rdoc/classes/Object.src/M000004.html +18 -0
  33. data/doc/rdoc/created.rid +1 -0
  34. data/doc/rdoc/files/CHANGELOG.html +136 -0
  35. data/doc/rdoc/files/README.html +326 -0
  36. data/doc/rdoc/files/lib/markaby/builder_rb.html +101 -0
  37. data/doc/rdoc/files/lib/markaby/cssproxy_rb.html +101 -0
  38. data/doc/rdoc/files/lib/markaby/helper_rb.html +101 -0
  39. data/doc/rdoc/files/lib/markaby/metaid_rb.html +107 -0
  40. data/doc/rdoc/files/lib/markaby/tags_rb.html +101 -0
  41. data/doc/rdoc/files/lib/markaby/template_rb.html +101 -0
  42. data/doc/rdoc/files/lib/markaby/view_rb.html +101 -0
  43. data/doc/rdoc/files/lib/markaby_rb.html +127 -0
  44. data/doc/rdoc/fr_class_index.html +33 -0
  45. data/doc/rdoc/fr_file_index.html +36 -0
  46. data/doc/rdoc/fr_method_index.html +51 -0
  47. data/doc/rdoc/index.html +24 -0
  48. data/doc/rdoc/rdoc-style.css +208 -0
  49. data/lib/markaby.rb +19 -1
  50. data/lib/markaby/builder.rb +106 -28
  51. data/lib/markaby/cssproxy.rb +9 -0
  52. data/lib/markaby/helper.rb +14 -0
  53. data/lib/markaby/tags.rb +3 -19
  54. data/setup.rb +1551 -0
  55. data/test/test_markaby.rb +53 -0
  56. data/tools/rakehelp.rb +100 -0
  57. metadata +103 -35
data/README ADDED
@@ -0,0 +1,189 @@
1
+ = Markaby (Markup as Ruby)
2
+
3
+ Markaby is a very short bit of code for writing HTML pages in pure Ruby.
4
+ It is an alternative to ERb which weaves the two languages together.
5
+ Also a replacement for templating languages which use primitive languages
6
+ that blend with HTML.
7
+
8
+ == Using Markaby as a Rails plugin
9
+
10
+ Write Rails templates in pure Ruby. Example layout:
11
+
12
+ html do
13
+ head do
14
+ title 'Products: ' + action_name
15
+ stylesheet_link_tag 'scaffold'
16
+ end
17
+
18
+ body do
19
+ p flash[:notice], :style => "color: green"
20
+
21
+ self << content_for_layout
22
+ end
23
+ end
24
+
25
+ == Using Markaby as a Ruby class
26
+
27
+ Markaby is flaming easy to call from your Ruby classes.
28
+
29
+ require 'markaby'
30
+
31
+ mab = Markaby::Builder.new
32
+ mab.html do
33
+ head { title "Boats.com" }
34
+ body do
35
+ h1 "Boats.com has great deals"
36
+ ul do
37
+ li "$49 for a canoe"
38
+ li "$39 for a raft"
39
+ li "$29 for a huge boot that floats and can fit 5 people"
40
+ end
41
+ end
42
+ end
43
+ puts mab.to_s
44
+
45
+ Markaby::Builder.new does take two arguments for passing in variables and
46
+ a helper object. You can also affix the block right on to the class.
47
+
48
+ See Markaby::Builder for all of that.
49
+
50
+ = A Note About <tt>instance_eval</tt>
51
+
52
+ The Markaby::Builder class is different from the normal Builder class,
53
+ since it uses <tt>instance_eval</tt> when running blocks. This cleans
54
+ up the appearance of the Markaby code you write. If <tt>instance_eval</tt>
55
+ was not used, the code would look like this:
56
+
57
+ mab = Markaby::Builder.new
58
+ mab.html do
59
+ mab.head { mab.title "Boats.com" }
60
+ mab.body do
61
+ mab.h1 "Boats.com has great deals"
62
+ end
63
+ end
64
+ puts mab.to_s
65
+
66
+ So, the advantage is the cleanliness of your code. The disadvantage is that
67
+ the block will run inside the Markaby::Builder object's scope. This means
68
+ that inside these blocks, <tt>self</tt> will be your Markaby::Builder object.
69
+ When you use instance variables in these blocks, they will be instance variables
70
+ of the Markaby::Builder object.
71
+
72
+ This doesn't effect Rails users, but when used in regular Ruby code, it can
73
+ be a bit disorienting. You are recommended to put your Markaby code in a
74
+ module where it won't mix with anything.
75
+
76
+ = A Note About Rails Helpers
77
+
78
+ When used in Rails templates, the Rails helper object is passed into
79
+ Markaby::Builder. When you call helper methods inside Markaby, the output
80
+ from those methods will be output to the stream. This is incredibly
81
+ handy, since most Rails helpers output HTML tags.
82
+
83
+ head do
84
+ javascript_include_tag 'prototype'
85
+ autodiscovery_link_tag
86
+ end
87
+
88
+ However, some methods are designed to give back a String which you can use
89
+ elsewhere. Call the <tt>@helpers</tt> object with the method and you'll get
90
+ the String back and nothing will be output.
91
+
92
+ p "Total is: #{@helper.number_to_human_size @file_bytes}"
93
+
94
+ Conversely, you may call instance variables from your controller by using
95
+ a method and its value will be returned, nothing will be output.
96
+
97
+ # Inside imaginary ProductController
98
+ def list
99
+ @products = Product.find :all
100
+ end
101
+
102
+ # Inside app/views/product/list.mab
103
+ products.each do |product|
104
+ p product.title
105
+ end
106
+
107
+ = A Quick Tour
108
+
109
+ If you dive right into Markaby, it'll probably make good sense, but you're
110
+ likely to run into a few kinks. Keep these pointers in mind and everything
111
+ will be fine.
112
+
113
+ == Element Classes
114
+
115
+ Element classes may be added by hooking methods onto container elements:
116
+
117
+ div.entry do
118
+ h2.entryTitle 'Son of WebPage'
119
+ div.entrySection %{by Anthony}
120
+ div.entryContent 'Okay, once again, the idea here is ...'
121
+ end
122
+
123
+ Which results in:
124
+
125
+ <div class="entry">
126
+ <h2 class="entryTitle">Son of WebPage</h2>
127
+ <div class="entrySection">by Anthony</div>
128
+ <div class="entryContent">Okay, once again, the idea here is ...</div>
129
+ </div>
130
+
131
+ == Element IDs
132
+
133
+ IDs may be added by the use of bang methods:
134
+
135
+ div.page!
136
+ div.content!
137
+ h1 "A Short Short Saintly Dog"
138
+ end
139
+ end
140
+
141
+ Which results in:
142
+
143
+ <div id="page">
144
+ <div id="content">
145
+ <h1>A Short Short Saintly Dog</h1>
146
+ </div>
147
+ </div>
148
+
149
+ == Markaby assumes XHTML 1.0 Transitional
150
+
151
+ Output defaults to XHTML 1.0 Transitional. To do XHTML 1.0 Strict,
152
+ try this:
153
+
154
+ xhtml_strict do
155
+ # innerds
156
+ end
157
+
158
+ == The <tt>capture</tt> Method
159
+
160
+ Want to catch a block of HTML as a string and play with it a bit?
161
+ Use the <tt>capture</tt> method.
162
+
163
+ Commonly used to join HTML blocks together:
164
+
165
+ div.menu! \
166
+ ['5.gets', 'bits', 'cult', 'inspect', '-h'].map do |category|
167
+ capture { link_to category }
168
+ end.
169
+ join( " | " )
170
+
171
+ == The <tt>tag!</tt> Method
172
+
173
+ If you need to force a tag at any time, call <tt>tag!</tt> with the
174
+ tag name followed by the possible arguments and block. The CssProxy
175
+ won't work with this technique.
176
+
177
+ tag! :select, :id => "country_list" do
178
+ countries.each do |country|
179
+ tag! :option, country
180
+ end
181
+ end
182
+
183
+ = Credits
184
+
185
+ Markaby is a work of immense hope by Tim Fletcher and why the lucky stiff.
186
+ Thankyou for giving it a whirl.
187
+
188
+ Markaby is inspired by the HTML library within cgi.rb. Hopefully it will
189
+ turn around and take some cues.
@@ -0,0 +1,15 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'tools/rakehelp'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ setup_tests
11
+ setup_rdoc ['README', 'CHANGELOG', 'lib/**/*.rb']
12
+
13
+ summary = "Markup as Ruby, write HTML in your native Ruby tongue"
14
+ test_file = "test/test_markaby.rb"
15
+ setup_gem("markaby", "0.3", "Tim Fletcher and _why", summary, ['builder'], test_file)
@@ -0,0 +1,192 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Markaby</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Markaby</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/markaby_rb.html">
59
+ lib/markaby.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/markaby/tags_rb.html">
63
+ lib/markaby/tags.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/markaby/builder_rb.html">
67
+ lib/markaby/builder.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/markaby/cssproxy_rb.html">
71
+ lib/markaby/cssproxy.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/markaby/view_rb.html">
75
+ lib/markaby/view.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/markaby/template_rb.html">
79
+ lib/markaby/template.rb
80
+ </a>
81
+ <br />
82
+ <a href="../files/lib/markaby/helper_rb.html">
83
+ lib/markaby/helper.rb
84
+ </a>
85
+ <br />
86
+ </td>
87
+ </tr>
88
+
89
+ </table>
90
+ </div>
91
+ <!-- banner header -->
92
+
93
+ <div id="bodyContent">
94
+
95
+
96
+
97
+ <div id="contextContent">
98
+
99
+ <div id="description">
100
+ <p>
101
+ <a href="Markaby.html">Markaby</a> is a module containing all of the great
102
+ <a href="Markaby.html">Markaby</a> classes that do such an excellent job.
103
+ </p>
104
+ <ul>
105
+ <li><a href="Markaby/Builder.html">Markaby::Builder</a>: the class for actually
106
+ calling the Ruby methods which write the HTML.
107
+
108
+ </li>
109
+ <li>Markaby::CSSProxy: a class which adds element classes and IDs to elements
110
+ when used within <a href="Markaby/Builder.html">Markaby::Builder</a>.
111
+
112
+ </li>
113
+ <li>Markaby::MetAid: metaprogramming helper methods.
114
+
115
+ </li>
116
+ <li>Markaby::Tags: lists the roles of various XHTML tags to help <a
117
+ href="Markaby/Builder.html">Builder</a> use these tags as they are
118
+ intended.
119
+
120
+ </li>
121
+ <li><a href="Markaby/Template.html">Markaby::Template</a>: a class for hooking
122
+ <a href="Markaby.html">Markaby</a> into Rails as a proper templating
123
+ language.
124
+
125
+ </li>
126
+ </ul>
127
+
128
+ </div>
129
+
130
+
131
+ </div>
132
+
133
+
134
+ </div>
135
+
136
+
137
+ <!-- if includes -->
138
+
139
+ <div id="section">
140
+
141
+ <div id="class-list">
142
+ <h3 class="section-bar">Classes and Modules</h3>
143
+
144
+ Module <a href="Markaby/ActionControllerHelper.html" class="link">Markaby::ActionControllerHelper</a><br />
145
+ Class <a href="Markaby/Builder.html" class="link">Markaby::Builder</a><br />
146
+ Class <a href="Markaby/CssProxy.html" class="link">Markaby::CssProxy</a><br />
147
+ Class <a href="Markaby/Template.html" class="link">Markaby::Template</a><br />
148
+ Class <a href="Markaby/View.html" class="link">Markaby::View</a><br />
149
+
150
+ </div>
151
+
152
+ <div id="constants-list">
153
+ <h3 class="section-bar">Constants</h3>
154
+
155
+ <div class="name-list">
156
+ <table summary="Constants">
157
+ <tr class="top-aligned-row context-row">
158
+ <td class="context-item-name">VERSION</td>
159
+ <td>=</td>
160
+ <td class="context-item-value">'0.3'</td>
161
+ </tr>
162
+ <tr class="top-aligned-row context-row">
163
+ <td class="context-item-name">TAGS</td>
164
+ <td>=</td>
165
+ <td class="context-item-value">[ :a, :abbr, :acronym, :span, :b, :caption, :del, :cite, :code, :col, :colgroup, :dd, :dfn, :dt, :em, :fieldset, :i, :img, :ins, :kbd, :p, :label, :legend, :li, :optgroup, :option, :select, :small, :span, :strong, :sub, :sup, :tbody, :td, :textarea, :thead, :title, :th, :tr, :tfoot, :tt, :address, :blockquote, :body, :div, :dl, :form, :h1, :h2, :h3, :head, :noscript, :object, :ol, :pre, :q, :samp, :script, :style, :table, :ul</td>
166
+ </tr>
167
+ <tr class="top-aligned-row context-row">
168
+ <td class="context-item-name">SELF_CLOSING_TAGS</td>
169
+ <td>=</td>
170
+ <td class="context-item-value">[ :hr, :br, :link, :meta, :input ]</td>
171
+ </tr>
172
+ </table>
173
+ </div>
174
+ </div>
175
+
176
+
177
+
178
+
179
+
180
+
181
+ <!-- if method_list -->
182
+
183
+
184
+ </div>
185
+
186
+
187
+ <div id="validator-badges">
188
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
189
+ </div>
190
+
191
+ </body>
192
+ </html>
@@ -0,0 +1,145 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Markaby::ActionControllerHelper</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Markaby::ActionControllerHelper</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/markaby/helper_rb.html">
59
+ lib/markaby/helper.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+ <div id="description">
76
+ <p>
77
+ <a href="../Markaby.html">Markaby</a> helpers for Rails.
78
+ </p>
79
+
80
+ </div>
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000005">render_markaby</a>&nbsp;&nbsp;
90
+ </div>
91
+ </div>
92
+
93
+ </div>
94
+
95
+
96
+ <!-- if includes -->
97
+
98
+ <div id="section">
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ <!-- if method_list -->
108
+ <div id="methods">
109
+ <h3 class="section-bar">Public Instance methods</h3>
110
+
111
+ <div id="method-M000005" class="method-detail">
112
+ <a name="M000005"></a>
113
+
114
+ <div class="method-heading">
115
+ <a href="ActionControllerHelper.src/M000005.html" target="Code" class="method-signature"
116
+ onclick="popupCode('ActionControllerHelper.src/M000005.html');return false;">
117
+ <span class="method-name">render_markaby</span><span class="method-args">(options = {}, &amp;block)</span>
118
+ </a>
119
+ </div>
120
+
121
+ <div class="method-description">
122
+ <p>
123
+ Returns a string of HTML built from the attached <tt>block</tt>. Any
124
+ <tt>options</tt> are passed into the render method.
125
+ </p>
126
+ <p>
127
+ Use this method in your controllers to output <a
128
+ href="../Markaby.html">Markaby</a> directly from inside.
129
+ </p>
130
+ </div>
131
+ </div>
132
+
133
+
134
+ </div>
135
+
136
+
137
+ </div>
138
+
139
+
140
+ <div id="validator-badges">
141
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
142
+ </div>
143
+
144
+ </body>
145
+ </html>