listify 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db56df7409febe4e7eca136242b96a5be612ae5e
4
+ data.tar.gz: 9a2e78bcb19ebaa5c1d100a1d56ece5edcd2dc5b
5
+ SHA512:
6
+ metadata.gz: cc7e873191030fae9b8fa3a9afbe4f8200d9e901e823af3cafadc650efd67bacc6b49e567ac3bbae35f9063f898d67641d940eff644ca173fbfbdab3d8de0014
7
+ data.tar.gz: 0d30d81a4e18a1eb89018065c0743d139b945f7e550434e91318a113eab3dc95ca875d200152df0d9cbacfd4cd31194a618b3f40dee3e8d014886289a7ce41cd
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ #Listify Rails Plugin
2
+
3
+ The Listify rails plugin provides a simple method to use in views and helpers to render an HTML list from a ruby array or hash.
4
+
5
+ ##Installation
6
+
7
+ ###Rails 3
8
+
9
+ Add the following line to your gemfile
10
+ ```
11
+ gem 'listify'
12
+ ```
13
+
14
+ ##Usage
15
+
16
+ ###Simple List
17
+
18
+ Arrays are rendered as simple lists:
19
+ ```
20
+ listify( ['first item', 'second item', 'third item'] )
21
+ => "<ul>
22
+ <li>first item</li>
23
+ <li>second item</li>
24
+ <li>third item</li>
25
+ </ul>"
26
+ ```
27
+ ###Multilevel lists
28
+
29
+ Hashes are rendered as a sub-list:
30
+ ```
31
+ listify( {'First Category' => ['item one', 'item two'], 'Second Category' => ['item three', 'item four'] } )
32
+ => "<ul>
33
+ <li>First Category
34
+ <ul>
35
+ <li>item one</li>
36
+ <li>item two</li>
37
+ </ul>
38
+ </li>
39
+ <li>Second Category
40
+ <ul>
41
+ <li>item three</li>
42
+ <li>item four</li>
43
+ </ul>
44
+ </li>
45
+ </ul>"
46
+ ```
47
+
48
+ ###Complex lists
49
+
50
+ And you can get more complex, though maybe you shouldn't:
51
+ ```
52
+ listify( {'First-Category' => ['item-one', 'item-two'],
53
+ 'Second-Category' =>['item-three',
54
+ 'item-four',
55
+ {'sub-cat-one' => [ 'sub-item-one',
56
+ 'sub-item-two',
57
+ { 'sub-sub-cat-one' => ['sub-sub-item-one', 'sub-sub-item-two'] }
58
+ ]
59
+ }
60
+ ],
61
+ 'Third-Item' => [],
62
+ 'Fourth-Item' => []}
63
+ }
64
+ )
65
+ => "<ul>
66
+ <li>First-Category
67
+ <ul>
68
+ <li>item-one</li>
69
+ <li>item-two</li>
70
+ </ul>
71
+ </li>
72
+ <li>Second-Category
73
+ <ul>
74
+ <li>item-three</li>
75
+ <li>item-four</li>
76
+ <li>sub-cat-one
77
+ <ul>
78
+ <li>sub-item-one</li>
79
+ <li>sub-item-two</li>
80
+ <li>sub-sub-cat-one
81
+ <ul>
82
+ <li>sub-sub-item-one</li>
83
+ <li>sub-sub-item-two</li>
84
+ </ul>
85
+ </li>
86
+ </ul>
87
+ </li>
88
+ </ul>
89
+ </li>
90
+ <li>Third-Item</li>
91
+ <li>Fourth-Item</li>
92
+ </ul>"
93
+ ```
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task :default => :spec
13
+
14
+ Bundler::GemHelper.install_tasks
15
+
data/lib/listify.rb ADDED
@@ -0,0 +1,46 @@
1
+ module Listify
2
+
3
+ module Helper
4
+
5
+ def listify(collection)
6
+ content_tag :ul do
7
+ concat list_items_for(collection)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def list_items_for(collection)
14
+ capture do
15
+ collection.each do |item|
16
+ if item.is_a?(Array)
17
+ concat sub_list(item[0], item[1])
18
+ else
19
+ concat content_tag :li, item
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def list_for_array(collection)
26
+ content_tag :ul do
27
+ collection.collect do |item|
28
+ if item.is_a?(Hash)
29
+ concat sub_list(item.to_a[0][0], item.to_a[0][1])
30
+ else
31
+ concat content_tag :li, item
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def sub_list(heading, items)
38
+ content_tag :li do
39
+ concat heading
40
+ concat list_for_array(items) unless items.empty?
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ ActionView::Base.send(:include, Listify::Helper) if defined?(ActionView::Base)
@@ -0,0 +1,3 @@
1
+ module Listify
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: listify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - 'Byron Appelt '
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.14
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.14
27
+ description: Rails plugin that generates HTML lists from ruby array and hash objects
28
+ email:
29
+ - byron.appelt@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/listify/version.rb
35
+ - lib/listify.rb
36
+ - MIT-LICENSE
37
+ - Rakefile
38
+ - README.md
39
+ homepage: http://bappelt.github.io/listify
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: HTML list generator plugin for Rails
62
+ test_files: []