listy 0.0.0 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/index.js +1 -0
- data/app/assets/javascripts/listy.js +55 -0
- data/lib/listy/engine.rb +4 -0
- data/lib/listy/railtie.rb +9 -0
- data/lib/listy/version.rb +3 -0
- data/lib/listy/view_helpers.rb +56 -0
- data/lib/listy.rb +3 -5
- data/listy.gemspec +17 -0
- metadata +18 -5
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Casey Li
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Listy
|
2
|
+
|
3
|
+
Listy is a Gem that contains a bunch of view helpers for use in Ruby on Rails to easily create different types of lists.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
Listy is only compatible with Rails 3.1 and above.
|
8
|
+
It leverages both the Asset Pipeline and the JQuery library.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'listy'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install listy
|
23
|
+
|
24
|
+
Listy also includes some Javascript assets, so be sure to add the following line to your application.js
|
25
|
+
|
26
|
+
//= require listy
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
There are a couple of helper method including:
|
31
|
+
|
32
|
+
### list_of_links(collection, display_method_name, css_class, show_more_index=5, empty_message="")
|
33
|
+
|
34
|
+
This method creates a simple unordered list of the elements in the collection.
|
35
|
+
|
36
|
+
### multi_column_list_of_links(collection, display_method_name, css_class, number_of_columns)
|
37
|
+
|
38
|
+
This does the same thing as list_of_links but presents it in the number of columns you specify.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./listy
|
@@ -0,0 +1,55 @@
|
|
1
|
+
$(function(){
|
2
|
+
$(".listy-tree .list-header").click(listHeaderClick);
|
3
|
+
$(".listy-show-more-link").click(toggleMoreList);
|
4
|
+
});
|
5
|
+
|
6
|
+
function listHeaderClick() {
|
7
|
+
var list = $(this).siblings("ul");
|
8
|
+
toggleList(list);
|
9
|
+
}
|
10
|
+
|
11
|
+
function toggleList(list) {
|
12
|
+
toggleList(200);
|
13
|
+
}
|
14
|
+
|
15
|
+
function toggleList(list, duration) {
|
16
|
+
|
17
|
+
var header = list.siblings(".list-header");
|
18
|
+
if(list.is(":visible")) {
|
19
|
+
list.slideUp(duration);
|
20
|
+
header.children(".icon").html("<i class='icon-angle-right'></i>");
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
list.slideDown(duration);
|
24
|
+
header.children(".icon").html("<i class='icon-angle-down'></i>");
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
function autoCollapseAllBut(headerName, tree) {
|
29
|
+
jQuery.each(tree.children("li"), function(){
|
30
|
+
|
31
|
+
var listHeaderText = $(this).children(".list-header").children(".list-header-text").html();
|
32
|
+
if(headerName != listHeaderText) {
|
33
|
+
toggleList($(this).children(".list-header").siblings("ul"), 0);
|
34
|
+
}
|
35
|
+
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
function toggleMoreList() {
|
40
|
+
toggleMoreList(200);
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
|
44
|
+
function toggleMoreList(duration) {
|
45
|
+
var showMoreList = $(this).siblings(".listy-show-more-list");
|
46
|
+
if(showMoreList.is(":visible")) {
|
47
|
+
showMoreList.slideUp(duration);
|
48
|
+
$(this).html("Show More");
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
showMoreList.slideDown(duration);
|
52
|
+
$(this).html("Show Less");
|
53
|
+
}
|
54
|
+
return false;
|
55
|
+
}
|
data/lib/listy/engine.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Listy
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
def list_of_links(collection, display_method_name, css_class, show_more_index=5, empty_message="")
|
5
|
+
if collection.present?
|
6
|
+
html = "<ul class='" + css_class + "'>"
|
7
|
+
show_more = false
|
8
|
+
collection.each_with_index do |element, index|
|
9
|
+
if index > show_more_index && !show_more
|
10
|
+
html += "<div class='listy-show-more-list' style='display:none'>"
|
11
|
+
show_more = true
|
12
|
+
end
|
13
|
+
html += "<li>" + link_to(element.try(display_method_name), element) + "</li>"
|
14
|
+
end
|
15
|
+
if show_more
|
16
|
+
html += "</div>"
|
17
|
+
html += link_to("Show More", "#", :class => "listy-show-more-link button orange-button")
|
18
|
+
end
|
19
|
+
html += "</ul>"
|
20
|
+
else
|
21
|
+
html = "There are no entries in this list."
|
22
|
+
html = empty_message if !empty_message.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
raw html
|
26
|
+
end
|
27
|
+
|
28
|
+
def multi_column_list_of_links(collection, display_method_name, css_class, number_of_columns)
|
29
|
+
html = ""
|
30
|
+
if collection.present?
|
31
|
+
number_of_entries_per_column = collection.size/number_of_columns
|
32
|
+
percentage_width_of_column = 100 / number_of_columns
|
33
|
+
Rails.logger.info(collection.size.to_s + " " + number_of_entries_per_column.to_s)
|
34
|
+
(0..number_of_columns-1).each do |i|
|
35
|
+
html += "<div style='float:left;width:" + percentage_width_of_column.to_s + "%'>"
|
36
|
+
|
37
|
+
start_index = i * number_of_entries_per_column
|
38
|
+
end_index = (i+1) * number_of_entries_per_column
|
39
|
+
end_index = collection.size if end_index > collection.size
|
40
|
+
|
41
|
+
html += list_of_links(collection[start_index..end_index], display_method_name, css_class, show_more_index=1000, "")
|
42
|
+
|
43
|
+
html += "</div>"
|
44
|
+
end
|
45
|
+
|
46
|
+
html += "<div style='clear:both'></div>"
|
47
|
+
|
48
|
+
else
|
49
|
+
html = "There are no entries in this list."
|
50
|
+
end
|
51
|
+
|
52
|
+
raw html
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/listy.rb
CHANGED
data/listy.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/listy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Casey Li"]
|
6
|
+
gem.email = ["casey.li@gmail.com"]
|
7
|
+
gem.description = %q{"A bunch of helpers to create fancy lists"}
|
8
|
+
gem.summary = %q{"Everything for list of links from collections to multi-column lists"}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "listy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Listy::VERSION
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,14 +11,27 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
email:
|
14
|
+
description: ! '"A bunch of helpers to create fancy lists"'
|
15
|
+
email:
|
16
|
+
- casey.li@gmail.com
|
16
17
|
executables: []
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- app/assets/javascripts/index.js
|
27
|
+
- app/assets/javascripts/listy.js
|
20
28
|
- lib/listy.rb
|
21
|
-
|
29
|
+
- lib/listy/engine.rb
|
30
|
+
- lib/listy/railtie.rb
|
31
|
+
- lib/listy/version.rb
|
32
|
+
- lib/listy/view_helpers.rb
|
33
|
+
- listy.gemspec
|
34
|
+
homepage: ''
|
22
35
|
licenses: []
|
23
36
|
post_install_message:
|
24
37
|
rdoc_options: []
|
@@ -41,5 +54,5 @@ rubyforge_project:
|
|
41
54
|
rubygems_version: 1.8.24
|
42
55
|
signing_key:
|
43
56
|
specification_version: 3
|
44
|
-
summary:
|
57
|
+
summary: ! '"Everything for list of links from collections to multi-column lists"'
|
45
58
|
test_files: []
|