listy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -4
- data/app/assets/javascripts/listy.js +13 -8
- data/lib/listy/version.rb +1 -1
- data/lib/listy/view_helpers.rb +25 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -27,15 +27,31 @@ Listy also includes some Javascript assets, so be sure to add the following line
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
There are a couple of helper
|
30
|
+
There are a couple of helper methods including:
|
31
31
|
|
32
|
-
|
32
|
+
listy_links(collection, display_method_name, css_class, show_more_index=5, empty_message="")
|
33
33
|
|
34
34
|
This method creates a simple unordered list of the elements in the collection.
|
35
35
|
|
36
|
-
|
36
|
+
multi_column_listy_links(collection, display_method_name, css_class, number_of_columns)
|
37
|
+
|
38
|
+
This does the same thing as listy_links but presents it in the number of columns you specify.
|
39
|
+
|
40
|
+
listy_tree(collection, spec, empty_message)
|
41
|
+
|
42
|
+
This method is for creating a nested tree of unordered lists for a collection with nested collections. This is suitable for Rails models that have has_many relationships.
|
43
|
+
|
44
|
+
Example let's say we have the following
|
45
|
+
|
46
|
+
* Country which has_many States
|
47
|
+
* State which has_many Cities
|
48
|
+
|
49
|
+
Typical usage would be:
|
50
|
+
|
51
|
+
listy_tree(Country.all, {:display_method_name => :name, :children => :states, :child => { :display_method_name => :name, :children => :cities, :child => {:display_method_name => :name, :children => nil, :child => nil}}}, "")
|
52
|
+
|
53
|
+
Be sure that the inner most child of the spec has :children => nil. This will stop the nesting.
|
37
54
|
|
38
|
-
This does the same thing as list_of_links but presents it in the number of columns you specify.
|
39
55
|
|
40
56
|
## Contributing
|
41
57
|
|
@@ -1,20 +1,20 @@
|
|
1
|
+
/*********************** LISTY TREE LIST **********************************************/
|
1
2
|
$(function(){
|
2
|
-
$(".listy-tree .list-header").click(
|
3
|
-
$(".listy-show-more-link").click(toggleMoreList);
|
3
|
+
$(".listy-tree .listy-tree-list-header").click(listyTreeListHeaderClick);
|
4
4
|
});
|
5
5
|
|
6
|
-
function
|
6
|
+
function listyTreeListHeaderClick() {
|
7
7
|
var list = $(this).siblings("ul");
|
8
|
-
|
8
|
+
toggleListyTreeList(list);
|
9
9
|
}
|
10
10
|
|
11
|
-
function
|
12
|
-
|
11
|
+
function toggleListyTreeList(list) {
|
12
|
+
toggleListyTreList(200);
|
13
13
|
}
|
14
14
|
|
15
|
-
function
|
15
|
+
function toggleListyTreeList(list, duration) {
|
16
16
|
|
17
|
-
var header = list.siblings(".list-header");
|
17
|
+
var header = list.siblings(".listy-tree-list-header");
|
18
18
|
if(list.is(":visible")) {
|
19
19
|
list.slideUp(duration);
|
20
20
|
header.children(".icon").html("<i class='icon-angle-right'></i>");
|
@@ -36,6 +36,11 @@ function autoCollapseAllBut(headerName, tree) {
|
|
36
36
|
});
|
37
37
|
}
|
38
38
|
|
39
|
+
/*********************** LISTY SHOW-MORE LIST ******************************************/
|
40
|
+
$(function(){
|
41
|
+
$(".listy-show-more-link").click(toggleMoreList);
|
42
|
+
});
|
43
|
+
|
39
44
|
function toggleMoreList() {
|
40
45
|
toggleMoreList(200);
|
41
46
|
return false;
|
data/lib/listy/version.rb
CHANGED
data/lib/listy/view_helpers.rb
CHANGED
@@ -1,7 +1,30 @@
|
|
1
1
|
module Listy
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
|
-
def
|
4
|
+
def listy_tree(collection, spec, empty_message)
|
5
|
+
if collection.present?
|
6
|
+
html = "<div class='listy-tree'>" + create_listy_tree(collection, spec, "", 0) + "</div>"
|
7
|
+
else
|
8
|
+
html = "There are no entries in this tree."
|
9
|
+
html = empty_message if !empty_message.nil?
|
10
|
+
end
|
11
|
+
raw html
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_listy_tree(collection, spec, html, level)
|
15
|
+
html += "<ul class='listy-tree-level-#{level}'>"
|
16
|
+
|
17
|
+
collection.each do |element|
|
18
|
+
html += "<li>"
|
19
|
+
html += "<div class='listy-tree-list-header'>#{element.try(spec[:display_method_name])}</div>"
|
20
|
+
html = create_listy_tree(element.try(spec[:children]), spec[:child], html, level+1) if !spec[:children].nil?
|
21
|
+
html += "</li>"
|
22
|
+
end
|
23
|
+
|
24
|
+
html += "</ul>"
|
25
|
+
end
|
26
|
+
|
27
|
+
def listy_links(collection, display_method_name, css_class, show_more_index=5, empty_message="")
|
5
28
|
if collection.present?
|
6
29
|
html = "<ul class='" + css_class + "'>"
|
7
30
|
show_more = false
|
@@ -25,7 +48,7 @@ module Listy
|
|
25
48
|
raw html
|
26
49
|
end
|
27
50
|
|
28
|
-
def
|
51
|
+
def multi_column_listy_links(collection, display_method_name, css_class, number_of_columns)
|
29
52
|
html = ""
|
30
53
|
if collection.present?
|
31
54
|
number_of_entries_per_column = collection.size/number_of_columns
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! '"A bunch of helpers to create fancy lists"'
|
15
15
|
email:
|