html_skeleton 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +5 -5
- data/lib/html_skeleton.rb +20 -23
- data/lib/html_skeleton_calendar.rb +19 -20
- data/lib/html_skeleton_table.rb +5 -6
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56db184d22751726492ac71403572cd8a2834d0181aadc3ba867c88308cd249d
|
4
|
+
data.tar.gz: da19bf08daca4345f61044155ea1e2829824614d02489bfdcb187f30cf6538f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbc2c9998eb15367256072d4c1963526f5225a72c5177a63d852ac587bf4f7a8aff7278c6558d2093a0eed9c9f1b2ced057cdfe65612112b99d9ed392d05c36a
|
7
|
+
data.tar.gz: 138ab21b89eb023bdaddeff721831a96cceb5b7e5b85ec457dee7d043ffb04f6ec888f0acc2aae57e19af2b05b77668b6c8f1522abfcb2752dcc451584905b44
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -47,7 +47,7 @@ Default Options
|
|
47
47
|
day_names: Date::DAYNAMES.dup,
|
48
48
|
month_names: Date::MONTHNAMES,
|
49
49
|
abbrev: (0..1),
|
50
|
-
cell_proc: block ||
|
50
|
+
cell_proc: block || ->(d) { d.day.to_s},
|
51
51
|
first_day_of_week: 1
|
52
52
|
|
53
53
|
|
@@ -80,7 +80,7 @@ Examples
|
|
80
80
|
}
|
81
81
|
|
82
82
|
stripes = %w{odd even}
|
83
|
-
proc =
|
83
|
+
proc = ->(row) { k = stripes.shift; stripes << k; %Q{class="#{k}"} }
|
84
84
|
HtmlSkeleton.new.table(@users, %w{email address},
|
85
85
|
tr_attribute: proc,
|
86
86
|
legend: 'Users') { |row, col|
|
@@ -92,10 +92,10 @@ Default Options
|
|
92
92
|
legend: nil,
|
93
93
|
col_legend: lambda(&:to_s),
|
94
94
|
row_legend: lambda(&:id),
|
95
|
-
th_attribute:
|
96
|
-
tr_attribute:
|
95
|
+
th_attribute: ->(col) { nil },
|
96
|
+
tr_attribute: ->(row) { nil },
|
97
97
|
table_class: 'skeleton',
|
98
|
-
cell_proc: block ||
|
98
|
+
cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>"}
|
99
99
|
|
100
100
|
|
101
101
|
Curious?
|
data/lib/html_skeleton.rb
CHANGED
@@ -7,35 +7,33 @@ class HtmlSkeleton
|
|
7
7
|
|
8
8
|
def calendar(options = {}, &block)
|
9
9
|
set_calendar_options(options, &block)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
%Q{<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>}
|
10
|
+
month = @options[:month]
|
11
|
+
frame = month ? 'div' : 'table'
|
12
|
+
body = month ? a_month(@options[:year], month) : a_year(@options[:year])
|
13
|
+
%(<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>)
|
15
14
|
end
|
16
15
|
|
17
16
|
def table(rows, cols, options = {}, &block)
|
18
17
|
set_table_options(options, &block)
|
19
|
-
|
20
|
-
<table class="#{@options[:table_class]}">
|
21
|
-
|
22
|
-
|
23
|
-
</table>
|
24
|
-
|
18
|
+
<<~TABLE
|
19
|
+
<table class="#{@options[:table_class]}">
|
20
|
+
#{table_header(cols)}
|
21
|
+
#{table_body(rows, cols)}
|
22
|
+
</table>
|
23
|
+
TABLE
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
26
|
protected
|
29
27
|
def set_calendar_options(options, &block)
|
30
28
|
year = DateTime.now.year
|
31
29
|
@options = {
|
32
|
-
year:
|
33
|
-
title:
|
34
|
-
rows:
|
30
|
+
year: year,
|
31
|
+
title: year,
|
32
|
+
rows: 3,
|
35
33
|
calendar_class: 'skeleton',
|
36
34
|
month_names: Date::MONTHNAMES,
|
37
|
-
abbrev:
|
38
|
-
cell_proc:
|
35
|
+
abbrev: (0..1),
|
36
|
+
cell_proc: block || ->(d) { d.day.to_s },
|
39
37
|
first_day_of_week: 1
|
40
38
|
}.merge options
|
41
39
|
|
@@ -44,8 +42,8 @@ class HtmlSkeleton
|
|
44
42
|
|
45
43
|
@day_header = names.collect { |day|
|
46
44
|
abbr = day[@options[:abbrev]]
|
47
|
-
str = abbr == day ? day : %
|
48
|
-
%
|
45
|
+
str = abbr == day ? day : %(<abbr title="#{day}">#{abbr}</abbr>)
|
46
|
+
%(<th scope="col">#{str}</th>)
|
49
47
|
}.join('')
|
50
48
|
end
|
51
49
|
|
@@ -54,12 +52,11 @@ class HtmlSkeleton
|
|
54
52
|
legend: nil,
|
55
53
|
col_legend: lambda(&:to_s),
|
56
54
|
row_legend: lambda(&:id),
|
57
|
-
th_attribute:
|
58
|
-
tr_attribute:
|
55
|
+
th_attribute: ->(_col) { nil },
|
56
|
+
tr_attribute: ->(_row) { nil },
|
59
57
|
|
60
58
|
table_class: 'skeleton',
|
61
|
-
cell_proc:
|
59
|
+
cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>" }
|
62
60
|
}.merge options
|
63
61
|
end
|
64
|
-
|
65
62
|
end
|
@@ -8,42 +8,42 @@ class HtmlSkeleton
|
|
8
8
|
def a_year(year)
|
9
9
|
rows = @options[:rows]
|
10
10
|
cols = 12 / rows
|
11
|
-
raise
|
11
|
+
raise 'html_skeleton_calendar: invalid option <rows>' unless rows * cols == 12
|
12
12
|
|
13
|
-
body = (0..rows - 1).collect {|y|
|
14
|
-
str = (1..cols).collect {|x| "<td>#{a_month(year, y * cols + x)}</td>"}
|
13
|
+
body = (0..rows - 1).collect { |y|
|
14
|
+
str = (1..cols).collect { |x| "<td>#{a_month(year, y * cols + x)}</td>" }
|
15
15
|
"<tr>#{str.join('')}</tr>"
|
16
16
|
}
|
17
|
-
|
18
|
-
<thead><th colspan="2">#{@options[:title]}</th></thead>
|
19
|
-
#{body.join('')}
|
20
|
-
|
17
|
+
<<~THEAD
|
18
|
+
<thead><th colspan="2">#{@options[:title]}</th></thead>
|
19
|
+
#{body.join('')}
|
20
|
+
THEAD
|
21
21
|
end
|
22
22
|
|
23
23
|
def a_month(year, month)
|
24
24
|
title = @options[:month_names][month]
|
25
|
-
|
26
|
-
<table class="month">
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
</table>
|
31
|
-
|
25
|
+
<<~TABLE
|
26
|
+
<table class="month">
|
27
|
+
<tr class="monthName"><th colspan="7">#{title}</th></tr>
|
28
|
+
<tr class="dayName">#{@day_header}</tr>
|
29
|
+
#{days_of_month(year, month)}
|
30
|
+
</table>
|
31
|
+
TABLE
|
32
32
|
end
|
33
33
|
|
34
34
|
def days_of_month(year, month)
|
35
35
|
first_weekday = @options[:first_day_of_week]
|
36
|
-
last_weekday = first_weekday
|
36
|
+
last_weekday = first_weekday.positive? ? first_weekday - 1 : 6
|
37
37
|
cell_proc = @options[:cell_proc]
|
38
|
-
|
39
|
-
|
38
|
+
bool = Time.respond_to?(:zone) && !(zone = Time.zone).nil?
|
39
|
+
today = bool ? zone.now.to_date : Date.today
|
40
40
|
|
41
41
|
first = Date.civil(year, month, 1)
|
42
42
|
last = Date.civil(year, month, -1)
|
43
43
|
|
44
44
|
cal = '<tr>'
|
45
45
|
cal << '<td></td>' * days_between(first_weekday, first.wday)
|
46
|
-
first.upto(last) {|cur|
|
46
|
+
first.upto(last) { |cur|
|
47
47
|
cal << a_day(cur, today, cell_proc)
|
48
48
|
cal << '</tr> <tr>' if cur.wday == last_weekday
|
49
49
|
}
|
@@ -58,7 +58,7 @@ class HtmlSkeleton
|
|
58
58
|
"<td class=\"#{attrs}\">#{block.call(date)}</td>"
|
59
59
|
# "<td class=\"#{attrs}\">##</td>"
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def weekend?(date)
|
63
63
|
[0, 6].include?(date.wday)
|
64
64
|
end
|
@@ -66,5 +66,4 @@ class HtmlSkeleton
|
|
66
66
|
def days_between(first, second)
|
67
67
|
first > second ? second + (7 - first) : second - first
|
68
68
|
end
|
69
|
-
|
70
69
|
end
|
data/lib/html_skeleton_table.rb
CHANGED
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
|
3
3
|
# table methods ######################################################
|
4
4
|
class HtmlSkeleton
|
5
|
-
|
5
|
+
protected
|
6
6
|
def table_header(cols)
|
7
7
|
legend = @options[:legend]
|
8
8
|
th_attribute = @options[:th_attribute]
|
@@ -12,7 +12,7 @@ class HtmlSkeleton
|
|
12
12
|
col_header = cols.collect { |col|
|
13
13
|
"<th #{th_attribute.call(col)}>#{proc.call(col)}</th>"
|
14
14
|
}.join
|
15
|
-
%
|
15
|
+
%(<thead><th class="legend">#{legend}</th>#{col_header}</thead>)
|
16
16
|
end
|
17
17
|
|
18
18
|
def table_body(rows, cols)
|
@@ -20,10 +20,10 @@ class HtmlSkeleton
|
|
20
20
|
row_legend = @options[:row_legend]
|
21
21
|
tr_attribute = @options[:tr_attribute]
|
22
22
|
rows.collect { |row|
|
23
|
-
rlegend =
|
24
|
-
|
23
|
+
rlegend = ''
|
24
|
+
rlegend = %(<td class="legend">#{row_legend.call(row)}</td>) if legend
|
25
25
|
cells = table_row(row, cols)
|
26
|
-
%
|
26
|
+
%(<tr #{tr_attribute.call(row)}>#{rlegend}#{cells}</tr>)
|
27
27
|
}.join("\n")
|
28
28
|
end
|
29
29
|
|
@@ -31,5 +31,4 @@ class HtmlSkeleton
|
|
31
31
|
cell_proc = @options[:cell_proc]
|
32
32
|
cols.collect { |col| cell_proc.call(row, col) }.join('')
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
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'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13'
|
27
41
|
description: |2
|
28
42
|
A simple helper for creating HTML calendars and tables.
|
29
43
|
|
@@ -60,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
requirements: []
|
63
|
-
rubygems_version: 3.0.
|
77
|
+
rubygems_version: 3.0.8
|
64
78
|
signing_key:
|
65
79
|
specification_version: 4
|
66
80
|
summary: A simple helper for creating HTML calendars and tables
|