html_skeleton 0.3.6 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +1 -1
- data/README.md +25 -23
- data/lib/html_skeleton.rb +29 -29
- data/lib/html_skeleton_calendar.rb +25 -22
- data/lib/html_skeleton_table.rb +8 -7
- metadata +41 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 257a4b33a0eeab346e831a3fbc7c68f32d1fb9e80abf203f3211b1ed8c020c3a
|
4
|
+
data.tar.gz: 64bb363bc93a4e2d9ea2a035daf45a1a25db7c90944b32ee6116789cea5038de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05b1b6a13f30ff52c60ba2da4ef461feb82f2b1220b54e08583e84fdf5b010073ff7c928d63d503ae909c3d4390bcaacc1b4a454d8d5d03bff0c2bb8a4df06a8
|
7
|
+
data.tar.gz: 2b8c3c6a928688b71ddf6191c6fe531ba95afef11a245f4f37b76518c1760733da9b381a2fd5255bb8d3a7e1660559fe546ac841f34b36677533a0948b98d528
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
HtmlSkeleton
|
2
2
|
============
|
3
|
+
[](http://badge.fury.io/rb/html_skeleton)
|
3
4
|
|
4
5
|
HtmlSkeleton provides the frame for a calendar or a table,
|
5
6
|
i.e. no loops are required to build up the HTML structure.
|
@@ -28,8 +29,8 @@ In the example below clicking a day triggers an action.
|
|
28
29
|
Examples
|
29
30
|
--------
|
30
31
|
HtmlSkeleton.new.calendar # calendar for current year
|
31
|
-
HtmlSkeleton.new.calendar :
|
32
|
-
HtmlSkeleton.new.calendar :
|
32
|
+
HtmlSkeleton.new.calendar year: 2012 # calendar for year 2012
|
33
|
+
HtmlSkeleton.new.calendar year: 2012, month: 8 # calendar for August 2012
|
33
34
|
|
34
35
|
HtmlSkeleton.new.calendar {|date|
|
35
36
|
link ="/#{controller_name}/toggle/#{@resource.id}?date=#{date}"
|
@@ -40,14 +41,15 @@ Examples
|
|
40
41
|
|
41
42
|
Default Options
|
42
43
|
---------------
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
44
|
+
year: DateTime.now.year,
|
45
|
+
title: DateTime.now.year,
|
46
|
+
rows: 3,
|
47
|
+
calendar_class: 'skeleton',
|
48
|
+
day_names: Date::DAYNAMES.dup,
|
49
|
+
month_names: Date::MONTHNAMES,
|
50
|
+
abbrev: (0..1),
|
51
|
+
cell_proc: block || ->(d) { d.day.to_s},
|
52
|
+
first_day_of_week: 1
|
51
53
|
|
52
54
|
|
53
55
|
Inspired by calendar_helper:
|
@@ -73,28 +75,28 @@ Examples
|
|
73
75
|
}
|
74
76
|
|
75
77
|
HtmlSkeleton.new.table(@users, %w{email address},
|
76
|
-
:
|
77
|
-
:
|
78
|
+
th_attribute: lambda { |col| col.name },
|
79
|
+
legend: 'Users') { |row, col|
|
78
80
|
"<td>#{ row.send(col) }</td>"
|
79
81
|
}
|
80
82
|
|
81
83
|
stripes = %w{odd even}
|
82
|
-
proc =
|
84
|
+
proc = ->(row) { k = stripes.shift; stripes << k; %Q{class="#{k}"} }
|
83
85
|
HtmlSkeleton.new.table(@users, %w{email address},
|
84
|
-
:
|
85
|
-
:
|
86
|
+
tr_attribute: proc,
|
87
|
+
legend: 'Users') { |row, col|
|
86
88
|
"<td>#{ row.send(col) }</td>"
|
87
89
|
}
|
88
90
|
|
89
91
|
Default Options
|
90
92
|
---------------
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
93
|
+
legend: nil,
|
94
|
+
col_legend: lambda(&:to_s),
|
95
|
+
row_legend: lambda(&:id),
|
96
|
+
th_attribute: ->(col) { nil },
|
97
|
+
tr_attribute: ->(row) { nil },
|
98
|
+
table_class: 'skeleton',
|
99
|
+
cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>"}
|
98
100
|
|
99
101
|
|
100
102
|
Curious?
|
@@ -108,4 +110,4 @@ Curious?
|
|
108
110
|
github.com/watu/table_builder
|
109
111
|
ruby-toolbox.com/projects/tableasy
|
110
112
|
|
111
|
-
Copyright (c) 2012 [Dittmar Krall], released under the MIT license.
|
113
|
+
Copyright (c) 2012-2019 [Dittmar Krall], released under the MIT license.
|
data/lib/html_skeleton.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require 'html_skeleton_calendar'
|
3
5
|
require 'html_skeleton_table'
|
@@ -7,35 +9,34 @@ class HtmlSkeleton
|
|
7
9
|
|
8
10
|
def calendar(options = {}, &block)
|
9
11
|
set_calendar_options(options, &block)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
%Q{<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>}
|
12
|
+
month = @options[:month]
|
13
|
+
frame = month ? 'div' : 'table'
|
14
|
+
body = month ? a_month(@options[:year], month) : a_year(@options[:year])
|
15
|
+
%(<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>)
|
15
16
|
end
|
16
17
|
|
17
18
|
def table(rows, cols, options = {}, &block)
|
18
19
|
set_table_options(options, &block)
|
19
|
-
|
20
|
-
<table class="#{@options[:table_class]}">
|
21
|
-
|
22
|
-
|
23
|
-
</table>
|
24
|
-
|
20
|
+
<<~TABLE
|
21
|
+
<table class="#{@options[:table_class]}">
|
22
|
+
#{table_header(cols)}
|
23
|
+
#{table_body(rows, cols)}
|
24
|
+
</table>
|
25
|
+
TABLE
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
28
|
protected
|
29
29
|
def set_calendar_options(options, &block)
|
30
30
|
year = DateTime.now.year
|
31
31
|
@options = {
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
32
|
+
year: year,
|
33
|
+
title: year,
|
34
|
+
rows: 3,
|
35
|
+
calendar_class: 'skeleton',
|
36
|
+
month_names: Date::MONTHNAMES,
|
37
|
+
abbrev: (0..1),
|
38
|
+
cell_proc: block || ->(d) { d.day.to_s },
|
39
|
+
first_day_of_week: 1
|
39
40
|
}.merge options
|
40
41
|
|
41
42
|
names = options[:day_names] || Date::DAYNAMES.dup
|
@@ -43,22 +44,21 @@ class HtmlSkeleton
|
|
43
44
|
|
44
45
|
@day_header = names.collect { |day|
|
45
46
|
abbr = day[@options[:abbrev]]
|
46
|
-
str = abbr == day ? day : %
|
47
|
-
%
|
47
|
+
str = abbr == day ? day : %(<abbr title="#{day}">#{abbr}</abbr>)
|
48
|
+
%(<th scope="col">#{str}</th>)
|
48
49
|
}.join('')
|
49
50
|
end
|
50
51
|
|
51
52
|
def set_table_options(options, &block)
|
52
53
|
@options = {
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
54
|
+
legend: nil,
|
55
|
+
col_legend: lambda(&:to_s),
|
56
|
+
row_legend: lambda(&:id),
|
57
|
+
th_attribute: ->(_col) { nil },
|
58
|
+
tr_attribute: ->(_row) { nil },
|
58
59
|
|
59
|
-
:
|
60
|
-
:
|
60
|
+
table_class: 'skeleton',
|
61
|
+
cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>" }
|
61
62
|
}.merge options
|
62
63
|
end
|
63
|
-
|
64
64
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
|
3
5
|
# calendar methods ###################################################
|
@@ -6,41 +8,44 @@ class HtmlSkeleton
|
|
6
8
|
|
7
9
|
protected
|
8
10
|
def a_year(year)
|
9
|
-
rows
|
10
|
-
|
11
|
-
|
11
|
+
rows = @options[:rows]
|
12
|
+
cols = 12 / rows
|
13
|
+
raise 'html_skeleton_calendar: invalid option <rows>' unless rows * cols == 12
|
14
|
+
|
15
|
+
body = (0..rows - 1).collect { |y|
|
16
|
+
str = (1..cols).collect { |x| "<td>#{a_month(year, y * cols + x)}</td>" }
|
12
17
|
"<tr>#{str.join('')}</tr>"
|
13
18
|
}
|
14
|
-
|
15
|
-
<thead><th colspan="2">#{@options[:title]}</th></thead>
|
16
|
-
#{body.join('')}
|
17
|
-
|
19
|
+
<<~THEAD
|
20
|
+
<thead><th colspan="2">#{@options[:title]}</th></thead>
|
21
|
+
#{body.join('')}
|
22
|
+
THEAD
|
18
23
|
end
|
19
24
|
|
20
25
|
def a_month(year, month)
|
21
26
|
title = @options[:month_names][month]
|
22
|
-
|
23
|
-
<table class="month">
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
</table>
|
28
|
-
|
27
|
+
<<~TABLE
|
28
|
+
<table class="month">
|
29
|
+
<tr class="monthName"><th colspan="7">#{title}</th></tr>
|
30
|
+
<tr class="dayName">#{@day_header}</tr>
|
31
|
+
#{days_of_month(year, month)}
|
32
|
+
</table>
|
33
|
+
TABLE
|
29
34
|
end
|
30
35
|
|
31
36
|
def days_of_month(year, month)
|
32
37
|
first_weekday = @options[:first_day_of_week]
|
33
|
-
last_weekday = first_weekday
|
38
|
+
last_weekday = first_weekday.positive? ? first_weekday - 1 : 6
|
34
39
|
cell_proc = @options[:cell_proc]
|
35
|
-
|
36
|
-
|
40
|
+
bool = Time.respond_to?(:zone) && !(zone = Time.zone).nil?
|
41
|
+
today = bool ? zone.now.to_date : Date.today
|
37
42
|
|
38
43
|
first = Date.civil(year, month, 1)
|
39
44
|
last = Date.civil(year, month, -1)
|
40
45
|
|
41
|
-
cal = '<tr>'
|
46
|
+
cal = '<tr>'.dup
|
42
47
|
cal << '<td></td>' * days_between(first_weekday, first.wday)
|
43
|
-
first.upto(last) {|cur|
|
48
|
+
first.upto(last) { |cur|
|
44
49
|
cal << a_day(cur, today, cell_proc)
|
45
50
|
cal << '</tr> <tr>' if cur.wday == last_weekday
|
46
51
|
}
|
@@ -53,9 +58,8 @@ class HtmlSkeleton
|
|
53
58
|
attrs += ' weekendDay' if weekend?(date)
|
54
59
|
attrs += ' today' if date == today
|
55
60
|
"<td class=\"#{attrs}\">#{block.call(date)}</td>"
|
56
|
-
# "<td class=\"#{attrs}\">##</td>"
|
57
61
|
end
|
58
|
-
|
62
|
+
|
59
63
|
def weekend?(date)
|
60
64
|
[0, 6].include?(date.wday)
|
61
65
|
end
|
@@ -63,5 +67,4 @@ class HtmlSkeleton
|
|
63
67
|
def days_between(first, second)
|
64
68
|
first > second ? second + (7 - first) : second - first
|
65
69
|
end
|
66
|
-
|
67
70
|
end
|
data/lib/html_skeleton_table.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
|
3
5
|
# table methods ######################################################
|
4
6
|
class HtmlSkeleton
|
5
|
-
|
7
|
+
protected
|
6
8
|
def table_header(cols)
|
7
9
|
legend = @options[:legend]
|
8
10
|
th_attribute = @options[:th_attribute]
|
9
|
-
return ''
|
11
|
+
return '' unless legend
|
10
12
|
|
11
13
|
proc = @options[:col_legend]
|
12
14
|
col_header = cols.collect { |col|
|
13
15
|
"<th #{th_attribute.call(col)}>#{proc.call(col)}</th>"
|
14
16
|
}.join
|
15
|
-
%
|
17
|
+
%(<thead><th class="legend">#{legend}</th>#{col_header}</thead>)
|
16
18
|
end
|
17
19
|
|
18
20
|
def table_body(rows, cols)
|
@@ -20,10 +22,10 @@ class HtmlSkeleton
|
|
20
22
|
row_legend = @options[:row_legend]
|
21
23
|
tr_attribute = @options[:tr_attribute]
|
22
24
|
rows.collect { |row|
|
23
|
-
rlegend =
|
24
|
-
|
25
|
+
rlegend = ''
|
26
|
+
rlegend = %(<td class="legend">#{row_legend.call(row)}</td>) if legend
|
25
27
|
cells = table_row(row, cols)
|
26
|
-
%
|
28
|
+
%(<tr #{tr_attribute.call(row)}>#{rlegend}#{cells}</tr>)
|
27
29
|
}.join("\n")
|
28
30
|
end
|
29
31
|
|
@@ -31,5 +33,4 @@ class HtmlSkeleton
|
|
31
33
|
cell_proc = @options[:cell_proc]
|
32
34
|
cols.collect { |col| cell_proc.call(row, col) }.join('')
|
33
35
|
end
|
34
|
-
|
35
36
|
end
|
metadata
CHANGED
@@ -1,64 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dittmar Krall
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement:
|
18
|
-
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
23
|
requirements:
|
20
|
-
- -
|
24
|
+
- - ">="
|
21
25
|
- !ruby/object:Gem::Version
|
22
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13'
|
23
34
|
type: :development
|
24
35
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
|
27
|
-
|
28
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13'
|
41
|
+
description: |2
|
42
|
+
A simple helper for creating HTML calendars and tables.
|
43
|
+
|
44
|
+
An example in a view: <%= HtmlSkeleton.new.calendar %>
|
45
|
+
|
46
|
+
The calendar/table may be embelished by user supplied lambda's,
|
47
|
+
e.g. for inserting link_to.
|
29
48
|
email: dittmar.krall@matique.de
|
30
49
|
executables: []
|
31
50
|
extensions: []
|
32
51
|
extra_rdoc_files: []
|
33
52
|
files:
|
53
|
+
- MIT-LICENSE
|
54
|
+
- README.md
|
34
55
|
- lib/html_skeleton.rb
|
35
56
|
- lib/html_skeleton_calendar.rb
|
36
57
|
- lib/html_skeleton_table.rb
|
37
|
-
- README.md
|
38
|
-
- MIT-LICENSE
|
39
|
-
has_rdoc: true
|
40
58
|
homepage: http://matique.de
|
41
|
-
licenses:
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata:
|
62
|
+
source_code_uri: https://github.com/matique/html_skeleton
|
42
63
|
post_install_message:
|
43
64
|
rdoc_options: []
|
44
65
|
require_paths:
|
45
66
|
- lib
|
46
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
68
|
requirements:
|
49
|
-
- -
|
69
|
+
- - ">="
|
50
70
|
- !ruby/object:Gem::Version
|
51
71
|
version: '0'
|
52
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
73
|
requirements:
|
55
|
-
- -
|
74
|
+
- - ">="
|
56
75
|
- !ruby/object:Gem::Version
|
57
76
|
version: '0'
|
58
77
|
requirements: []
|
59
|
-
|
60
|
-
rubygems_version: 1.6.2
|
78
|
+
rubygems_version: 3.2.6
|
61
79
|
signing_key:
|
62
|
-
specification_version:
|
80
|
+
specification_version: 4
|
63
81
|
summary: A simple helper for creating HTML calendars and tables
|
64
82
|
test_files: []
|