Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed error in the README and added <ol> and <ul> to Arrays

  • Loading branch information...
commit 587ee9e41d17840f6b4ab1eab7ee9aedc7aa7660 1 parent 8406fd8
@jocke authored
Showing with 70 additions and 6 deletions.
  1. +21 −6 README.markdown
  2. +18 −0 lib/taggart.rb
  3. +31 −0 spec/taggart_spec.rb
View
27 README.markdown
@@ -93,7 +93,7 @@ Like this:
gives you
```html
- <script id="pants_pants" type="text/javascript">alert('This string will pop up an alert!')</script>"
+ <script type="text/javascript">alert('This string will pop up an alert!')</script>
```
whereas this string
@@ -105,13 +105,27 @@ whereas this string
gives you this
```html
- "<script type="text/javascript" src="/script/awesome_script.js"></script>"
+ <script type="text/javascript" src="/script/awesome_script.js"></script>
```
-Naturally this also works with attributes.
+Calling `.ol` or `.ul` on an array, will generate a full ordered or unordered list, like this
+
+```ruby
+ %w(First Second Third).ol
+```
+
+returns
+
+```html
+ <ol><li>First</li><li>Second</li><li>Third</li></ol>
+```
+
+
+Naturally they all also work with attributes.
See the `spec/taggart_spec.rb` for more examples (until I have time to do a bigger-better-faster-example file).
+
Background:
-----------
I have a lot of Ruby code that marks some String in an HTML tag, usually with a
@@ -150,9 +164,10 @@ Taggart is now active, which means you can play around.
History
-------
+- Added `<ol>` and `<ul>` tags to the Array so you can now generate lists in one fast action.
- Added `<script>`-tag. You can now add `"my-script.js".script` and `"alert('Hello World!')".script`.
- Added several tags (still not a complete list, tweet or send a pull request for more tags.)
-- Removed several 'if DEBUG' lines
+- Removed several `if DEBUG` lines
- Removed examples and most comments from taggart.rb file
- Converted the README to markdown for a bit better formatting fun.
- Added `.href` and `.img` feature.
@@ -191,8 +206,8 @@ Feedback welcome!!
Author: Jocke Selin <jocke@selincite.com> @jockeselin
-Date: 2012-03-09
+Date: 2012-03-13
-Version: 0.0.5 Build 010
+Version: 0.0.6 Build 011
Github: <https://github.com/jocke/taggart>
View
18 lib/taggart.rb
@@ -159,6 +159,24 @@ def self.array_attribute_tag(tag, tag_name = nil)
end
+ def ol(*args)
+ self.li.ol(*args)
+ end
+
+
+ def ul(*args)
+ self.li.ul(*args)
+ end
+
+
+ def tr(*args)
+ self.td.tr(*args)
+ end
+
+ # def table(*args)
+ # puts "Not implemented. Should return a table, with a TR for each nested array, or one TR if there's only one array."
+ # end
+
end # End Array module
end
View
31 spec/taggart_spec.rb
@@ -195,4 +195,35 @@
end
end
end
+
+ describe Taggart::Array, "smarter tags" do
+ context "cleverer lists" do
+ it "returns an ordered list when calling ol." do
+ %w{one two three}.ol.should == "<ol><li>one</li><li>two</li><li>three</li></ol>"
+ end
+
+ it "returns an ordered list with attributes when calling ol." do
+ %w{one two three}.ol(id: :my_unordered_list).should == "<ol id=\"my_unordered_list\"><li>one</li><li>two</li><li>three</li></ol>"
+ end
+
+ it "returns an unordered list when calling ul." do
+ %w{one two three}.ul.should == "<ul><li>one</li><li>two</li><li>three</li></ul>"
+ end
+
+ it "returns an unordered list with attributes when calling ol." do
+ %w{one two three}.ul(id: :my_ordered_list).should == "<ul id=\"my_ordered_list\"><li>one</li><li>two</li><li>three</li></ul>"
+ end
+
+ end
+ context "cleverer tables" do
+
+ it "returns a table row when calling tr." do
+ %w{one two three}.tr.should == "<tr><td>one</td><td>two</td><td>three</td></tr>"
+ end
+
+ it "returns an unordered list with attributes when calling ol." do
+ %w{one two three}.tr(id: :my_table_row).should == "<tr id=\"my_table_row\"><td>one</td><td>two</td><td>three</td></tr>"
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.