Skip to content

Commit

Permalink
Fixed error in the README and added <ol> and <ul> to Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jocke committed Mar 13, 2012
1 parent 8406fd8 commit 587ee9e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
27 changes: 21 additions & 6 deletions README.markdown
Expand Up @@ -93,7 +93,7 @@ Like this:
gives you gives you


```html ```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 whereas this string
Expand All @@ -105,13 +105,27 @@ whereas this string
gives you this gives you this


```html ```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). See the `spec/taggart_spec.rb` for more examples (until I have time to do a bigger-better-faster-example file).



Background: Background:
----------- -----------
I have a lot of Ruby code that marks some String in an HTML tag, usually with a I have a lot of Ruby code that marks some String in an HTML tag, usually with a
Expand Down Expand Up @@ -150,9 +164,10 @@ Taggart is now active, which means you can play around.
History 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 `<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.) - 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 - Removed examples and most comments from taggart.rb file
- Converted the README to markdown for a bit better formatting fun. - Converted the README to markdown for a bit better formatting fun.
- Added `.href` and `.img` feature. - Added `.href` and `.img` feature.
Expand Down Expand Up @@ -191,8 +206,8 @@ Feedback welcome!!


Author: Jocke Selin <jocke@selincite.com> @jockeselin 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> Github: <https://github.com/jocke/taggart>
18 changes: 18 additions & 0 deletions lib/taggart.rb
Expand Up @@ -159,6 +159,24 @@ def self.array_attribute_tag(tag, tag_name = nil)
end 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 # End Array module
end end


Expand Down
31 changes: 31 additions & 0 deletions spec/taggart_spec.rb
Expand Up @@ -195,4 +195,35 @@
end end
end 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 end

0 comments on commit 587ee9e

Please sign in to comment.