html_skeleton 0.4.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 43dd93d55ec87d5e024b088ae78c7878618a46fc
4
- data.tar.gz: 5de99008a76f63eaee5cf2e1b5f70b71257defae
2
+ SHA256:
3
+ metadata.gz: e29dd94798168a8ab8267eed2aaf79df55206eebdc08529fa4d3105959761a7c
4
+ data.tar.gz: e42c7b766fd842f825e8c53b2e32652c8535728e9a67360de5b0deffafb9d364
5
5
  SHA512:
6
- metadata.gz: 667f0653eaffc91e4f4d34de378f93f0d05ade478ef44982cc79f15518bfa52897a38fcb509485e09175838c36f28b07ff8a5c92d46281a74693abc8262d20e9
7
- data.tar.gz: f334d20f9e254b9740b0d36c2dbf004e7a1f63bccd8fb7257cd7770f270d8c629455b18d31e5ffa8f287e0785021ea922a6d3323643029246f4de80d7f512625
6
+ metadata.gz: f1866ed93d9c6e5c2a8bb055c9a8a1529bb7117429ee8ffa57adf371902e7e373306c2ef30968f9f57a7e5e18056c0c5f5b79f36f822e69e2544f94e75769d1b
7
+ data.tar.gz: 8bb4b6fd8ca2d34f18af0fe5850a5ab9cab30b03a0792aa94a11c637fe45265f2df9216dd2686d11a98f368fc6d9b16ef4bf1c3d8c21185f0e1bf42fddf5f622
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012-2015 Dittmar Krall - http://matique.de
1
+ Copyright 2012-2021 Dittmar Krall - www.matique.com
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  HtmlSkeleton
2
2
  ============
3
+ [![Gem Version](https://badge.fury.io/rb/html_skeleton.png)](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.
@@ -47,7 +48,7 @@ Default Options
47
48
  day_names: Date::DAYNAMES.dup,
48
49
  month_names: Date::MONTHNAMES,
49
50
  abbrev: (0..1),
50
- cell_proc: block || lambda {|d| d.day.to_s},
51
+ cell_proc: block || ->(d) { d.day.to_s},
51
52
  first_day_of_week: 1
52
53
 
53
54
 
@@ -80,7 +81,7 @@ Examples
80
81
  }
81
82
 
82
83
  stripes = %w{odd even}
83
- proc = lambda{ |row| k = stripes.shift; stripes << k; %Q{class="#{k}"} }
84
+ proc = ->(row) { k = stripes.shift; stripes << k; %Q{class="#{k}"} }
84
85
  HtmlSkeleton.new.table(@users, %w{email address},
85
86
  tr_attribute: proc,
86
87
  legend: 'Users') { |row, col|
@@ -90,12 +91,12 @@ Examples
90
91
  Default Options
91
92
  ---------------
92
93
  legend: nil,
93
- col_legend: lambda(&:to_s),
94
- row_legend: lambda(&:id),
95
- th_attribute: lambda { |col| nil },
96
- tr_attribute: lambda { |row| nil },
94
+ col_legend: ->(x) { x.to_s },
95
+ row_legend: ->(x) { x.id },
96
+ th_attribute: ->(col) { nil },
97
+ tr_attribute: ->(row) { nil },
97
98
  table_class: 'skeleton',
98
- cell_proc: block || lambda {|row, col| "<td>#{row} #{col}</td>"}
99
+ cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>"}
99
100
 
100
101
 
101
102
  Curious?
@@ -109,4 +110,4 @@ Curious?
109
110
  github.com/watu/table_builder
110
111
  ruby-toolbox.com/projects/tableasy
111
112
 
112
- Copyright (c) 2012-2015 [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,33 @@ class HtmlSkeleton
7
9
 
8
10
  def calendar(options = {}, &block)
9
11
  set_calendar_options(options, &block)
10
- frame = @options[:month] ? 'div' : 'table'
11
- body = @options[:month] ?
12
- a_month(@options[:year], @options[:month]) :
13
- a_year(@options[:year])
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
- <<-EOS
20
- <table class="#{@options[:table_class]}">
21
- #{table_header(cols)}
22
- #{table_body(rows, cols)}
23
- </table>
24
- EOS
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
- year: year,
33
- title: year,
34
- rows: 3,
32
+ year: year,
33
+ title: year,
34
+ rows: 3,
35
35
  calendar_class: 'skeleton',
36
36
  month_names: Date::MONTHNAMES,
37
- abbrev: (0..1),
38
- cell_proc: block || lambda {|d| d.day.to_s},
37
+ abbrev: (0..1),
38
+ cell_proc: block || ->(d) { d.day.to_s },
39
39
  first_day_of_week: 1
40
40
  }.merge options
41
41
 
@@ -44,22 +44,21 @@ class HtmlSkeleton
44
44
 
45
45
  @day_header = names.collect { |day|
46
46
  abbr = day[@options[:abbrev]]
47
- str = abbr == day ? day : %Q{<abbr title='#{day}'>#{abbr}</abbr>}
48
- %Q{<th scope='col'>#{str}</th>}
49
- }.join('')
47
+ str = abbr == day ? day : %(<abbr title="#{day}">#{abbr}</abbr>)
48
+ %(<th scope="col">#{str}</th>)
49
+ }.join
50
50
  end
51
51
 
52
52
  def set_table_options(options, &block)
53
53
  @options = {
54
54
  legend: nil,
55
- col_legend: lambda(&:to_s),
56
- row_legend: lambda(&:id),
57
- th_attribute: lambda { |col| nil },
58
- tr_attribute: lambda { |row| nil },
55
+ col_legend: ->(x) { x.to_s },
56
+ row_legend: ->(x) { x.id },
57
+ th_attribute: ->(_col) {},
58
+ tr_attribute: ->(_row) {},
59
59
 
60
60
  table_class: 'skeleton',
61
- cell_proc: block || lambda {|row, col| "<td>#{row} #{col}</td>"},
61
+ cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>" }
62
62
  }.merge options
63
63
  end
64
-
65
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  # calendar methods ###################################################
@@ -8,42 +10,42 @@ class HtmlSkeleton
8
10
  def a_year(year)
9
11
  rows = @options[:rows]
10
12
  cols = 12 / rows
11
- raise "html_skeleton_calendar: invalid option <rows>" unless rows * cols == 12
13
+ raise 'html_skeleton_calendar: invalid option <rows>' unless rows * cols == 12
12
14
 
13
- body = (0..rows - 1).collect {|y|
14
- str = (1..cols).collect {|x| "<td>#{a_month(year, y * cols + x)}</td>"}
15
- "<tr>#{str.join('')}</tr>"
15
+ body = (0..rows - 1).collect { |y|
16
+ str = (1..cols).collect { |x| "<td>#{a_month(year, y * cols + x)}</td>" }
17
+ "<tr>#{str.join}</tr>"
16
18
  }
17
- <<-EOS
18
- <thead><th colspan="2">#{@options[:title]}</th></thead>
19
- #{body.join('')}
20
- EOS
19
+ <<~THEAD
20
+ <thead><th colspan="2">#{@options[:title]}</th></thead>
21
+ #{body.join}
22
+ THEAD
21
23
  end
22
24
 
23
25
  def a_month(year, month)
24
26
  title = @options[:month_names][month]
25
- <<-EOS
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
- EOS
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
32
34
  end
33
35
 
34
36
  def days_of_month(year, month)
35
37
  first_weekday = @options[:first_day_of_week]
36
- last_weekday = first_weekday > 0 ? first_weekday - 1 : 6
38
+ last_weekday = first_weekday.positive? ? first_weekday - 1 : 6
37
39
  cell_proc = @options[:cell_proc]
38
- today = (Time.respond_to?(:zone) &&
39
- !(zone = Time.zone).nil? ? zone.now.to_date : Date.today)
40
+ bool = Time.respond_to?(:zone) && !(zone = Time.zone).nil?
41
+ today = bool ? zone.now.to_date : Date.today
40
42
 
41
43
  first = Date.civil(year, month, 1)
42
44
  last = Date.civil(year, month, -1)
43
45
 
44
- cal = '<tr>'
46
+ cal = +'<tr>'
45
47
  cal << '<td></td>' * days_between(first_weekday, first.wday)
46
- first.upto(last) {|cur|
48
+ first.upto(last) { |cur|
47
49
  cal << a_day(cur, today, cell_proc)
48
50
  cal << '</tr> <tr>' if cur.wday == last_weekday
49
51
  }
@@ -56,9 +58,8 @@ class HtmlSkeleton
56
58
  attrs += ' weekendDay' if weekend?(date)
57
59
  attrs += ' today' if date == today
58
60
  "<td class=\"#{attrs}\">#{block.call(date)}</td>"
59
- # "<td class=\"#{attrs}\">##</td>"
60
61
  end
61
-
62
+
62
63
  def weekend?(date)
63
64
  [0, 6].include?(date.wday)
64
65
  end
@@ -66,5 +67,4 @@ class HtmlSkeleton
66
67
  def days_between(first, second)
67
68
  first > second ? second + (7 - first) : second - first
68
69
  end
69
-
70
70
  end
@@ -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
- protected
7
+ protected
6
8
  def table_header(cols)
7
9
  legend = @options[:legend]
8
10
  th_attribute = @options[:th_attribute]
9
- return '' unless legend
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
- %Q{<thead><th class="legend">#{legend}</th>#{col_header}</thead>}
17
+ %(<thead><th class="legend">#{legend}</th>#{col_header}</thead>)
16
18
  end
17
19
 
18
20
  def table_body(rows, cols)
@@ -20,16 +22,15 @@ class HtmlSkeleton
20
22
  row_legend = @options[:row_legend]
21
23
  tr_attribute = @options[:tr_attribute]
22
24
  rows.collect { |row|
23
- rlegend = legend ? %Q{<td class="legend">#{row_legend.call(row)}</td>}
24
- : ''
25
+ rlegend = ''
26
+ rlegend = %(<td class="legend">#{row_legend.call(row)}</td>) if legend
25
27
  cells = table_row(row, cols)
26
- %Q{<tr #{tr_attribute.call(row)}>#{rlegend}#{cells}</tr>}
28
+ %(<tr #{tr_attribute.call(row)}>#{rlegend}#{cells}</tr>)
27
29
  }.join("\n")
28
30
  end
29
31
 
30
32
  def table_row(row, cols)
31
33
  cell_proc = @options[:cell_proc]
32
- cols.collect { |col| cell_proc.call(row, col) }.join('')
34
+ cols.collect { |col| cell_proc.call(row, col) }.join
33
35
  end
34
-
35
36
  end
metadata CHANGED
@@ -1,27 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
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
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  description: |2
@@ -44,7 +58,8 @@ files:
44
58
  homepage: http://matique.de
45
59
  licenses:
46
60
  - MIT
47
- metadata: {}
61
+ metadata:
62
+ source_code_uri: https://github.com/matique/html_skeleton
48
63
  post_install_message:
49
64
  rdoc_options: []
50
65
  require_paths:
@@ -60,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
75
  - !ruby/object:Gem::Version
61
76
  version: '0'
62
77
  requirements: []
63
- rubyforge_project:
64
- rubygems_version: 2.4.5
78
+ rubygems_version: 3.2.6
65
79
  signing_key:
66
80
  specification_version: 4
67
81
  summary: A simple helper for creating HTML calendars and tables