dieses 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4b0aef1ab9d5ec62887c01edb5a4e85f32368d66106e4e9b861a828a41277f9
4
- data.tar.gz: e55e26f76024125ec93a6e8d04bb503cbc2a4e3eb51ec6943f7d513482b93083
3
+ metadata.gz: 2853498dbdb4547423d4974f7e496ee6e97f9ecc879cc8ae0e72efcb7d3c7ea5
4
+ data.tar.gz: b01845c3815d257b6d5ac96bd88cab77a71b00cfe552d0fe8076e6fc91914541
5
5
  SHA512:
6
- metadata.gz: bdd09ad3cbbcb96463584f3b40cf022252124326930782febdc507b40e2ba32c4d8a91fd0b5a66c9e83d4a44df6e08f00d5e92b242989982257dc00e399e3945
7
- data.tar.gz: e1a1b74ccdb5773284331d451379e2e287368d11a209d8001ee41ac5d5020dff9dc3eee008365035477ffae88bc24151c7fa2edbb1ffcf0be8b1b4ff278c7b33
6
+ metadata.gz: 2dffcb272a37ef6c6c21f34733613fc56cd3c16c26e81d17db5420f60d16a3c5beae19f5c1dd72ddeef9616d83ecbfb068a7e08b3088fea4a417989ef54e4d0f
7
+ data.tar.gz: 4fc3e0b3a711437c41514ddeb885a6bc99e484d31090e3f0f802c841c35c26f421d8a50abbbfeaee412da53d4b8097c325384141a3303a3886b9d7b79d1bbb06
data/CHANGELOG.md CHANGED
@@ -3,12 +3,22 @@ Changelog
3
3
 
4
4
  All notable changes to this project will be documented in this file.
5
5
 
6
- [0.0.0] - 2021-08-09
6
+ [0.0.2] - 2021-08-21
7
7
  --------------------
8
8
 
9
- Initial release.
9
+ ### Changed
10
+
11
+ - Use inline CSS for styling
12
+ - Fix left over names
13
+ - Bump Ruby version to 3.0.2
10
14
 
11
15
  [0.0.1] - 2021-08-09
12
16
  --------------------
13
17
 
14
18
  New release for the new project name.
19
+
20
+ [0.0.0] - 2021-08-09
21
+ --------------------
22
+
23
+ Initial release.
24
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Diesis
1
+ Dieses
2
2
  ======
3
3
 
4
4
  [![test](https://github.com/alaturka/dieses/actions/workflows/test.yml/badge.svg)](https://github.com/alaturka/dieses/actions/workflows/test.yml)
@@ -8,8 +8,14 @@ module Dieses
8
8
  TEMPLATE = <<~XML
9
9
  <?xml version="1.0" standalone="no"?>
10
10
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
11
- <svg xmlns="http://www.w3.org/2000/svg" width="%{width}mm" height="%{height}mm" viewBox="0 0 %{width} %{height}" %{header}>
12
- %{style}
11
+ <svg xmlns="http://www.w3.org/2000/svg" width="%{width}mm" height="%{height}mm" viewBox="0 0 %{width} %{height}" shape-rendering="geometricPrecision" %{header}>
12
+ <style>
13
+ svg { stroke: %{color}; stroke-width: %{medium}; }
14
+ .altcolor { stroke: %{altcolor}; }
15
+ .thin { stroke-width: %{thin}; }
16
+ .thick { stroke-width: %{thick}; }
17
+ .dashed { stroke-dasharray: %{dashed}; }
18
+ </style>
13
19
  <g id="sheet">
14
20
  %{content}
15
21
  </g>
@@ -25,10 +31,6 @@ module Dieses
25
31
  @elements = Set.new
26
32
  end
27
33
 
28
- def to_h
29
- @paper.to_h
30
- end
31
-
32
34
  def <<(items)
33
35
  [*items].each do |item|
34
36
  case item
@@ -39,12 +41,31 @@ module Dieses
39
41
  end
40
42
  end
41
43
 
42
- def render(header: EMPTY_STRING, style: EMPTY_STRING)
43
- # We avoid prettifying XML through REXML which is pretty slow, at the cost of some ugly hacks.
44
- format(TEMPLATE, **to_h,
44
+ def render(header: EMPTY_STRING, variables: EMPTY_HASH)
45
+ # We avoid prettifying XML through REXML which is pretty slow, at the cost of a somewhat hacky code.
46
+ format(TEMPLATE, **variables(**variables),
45
47
  content: Geometry.to_svg(elements, paper, prefix: ' ' * 4),
46
- header: header,
47
- style: style.empty? ? '' : format('<style>%{style}</style>', style: style))
48
+ header: header)
49
+ end
50
+
51
+ private
52
+
53
+ DEFAULT_COLOR = '#ed008c'
54
+ DEFAULT_ALTCOLOR = 'blue'
55
+ DEFAULT_LINEWIDTH = 0.04
56
+ DEFAULT_DASHES = [2, 2].freeze
57
+
58
+ def variables(**kwargs) # rubocop:disable Metrics/PerceivedComplexity
59
+ paper.to_h.merge(kwargs).tap do |variables|
60
+ linewidth = (variables[:medium] || DEFAULT_LINEWIDTH).to_f
61
+
62
+ variables[:color] ||= DEFAULT_COLOR
63
+ variables[:altcolor] ||= DEFAULT_ALTCOLOR
64
+ variables[:medium] ||= linewidth.to_s
65
+ variables[:thick] ||= (linewidth * 2.0).to_s
66
+ variables[:thin] ||= (linewidth / 2.0).to_s
67
+ variables[:dashed] ||= DEFAULT_DASHES.map(&:to_s).join(' ')
68
+ end
48
69
  end
49
70
  end
50
71
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'diesis'
3
+ require 'dieses'
4
4
 
5
5
  require_relative 'cli/single'
6
6
  require_relative 'cli/multi'
@@ -5,20 +5,20 @@ module Dieses
5
5
  module Mixins
6
6
  module Lines
7
7
  module ClassMethods
8
- Line = Struct.new :tag, :after, :style, :step, keyword_init: true
8
+ Line = Struct.new :tags, :after, :style, :step, keyword_init: true
9
9
 
10
- def hline(tag, after: Undefined, style: EMPTY_HASH)
11
- (param.hlines ||= []) << Line.new(tag: tag, after: after, style: style)
10
+ def hline(*tags, after: Undefined, style: EMPTY_HASH)
11
+ (param.hlines ||= []) << Line.new(tags: tags, after: after, style: style)
12
12
  end
13
13
 
14
- def vline(tag, after: Undefined, style: EMPTY_HASH)
15
- (param.vlines ||= []) << Line.new(tag: tag, after: after, style: style)
14
+ def vline(*tags, after: Undefined, style: EMPTY_HASH)
15
+ (param.vlines ||= []) << Line.new(tags: tags, after: after, style: style)
16
16
  end
17
17
 
18
- Cross = Struct.new :tag, :angle, :style, keyword_init: true
18
+ Cross = Struct.new :tags, :angle, :style, keyword_init: true
19
19
 
20
- def cline(tag, angle:, style: EMPTY_HASH)
21
- (param.clines ||= []) << Cross.new(tag: tag, angle: angle, style: style)
20
+ def cline(*tags, angle:, style: EMPTY_HASH)
21
+ (param.clines ||= []) << Cross.new(tags: tags, angle: angle, style: style)
22
22
  end
23
23
  end
24
24
 
@@ -55,7 +55,7 @@ module Dieses
55
55
  draw unit: unit, multiple: multiple do
56
56
  repeat do
57
57
  param.hlines.each do |line|
58
- hline line.tag, style: line.style
58
+ hline(*line.tags, style: line.style)
59
59
  down line.step
60
60
  end
61
61
  end
@@ -70,7 +70,7 @@ module Dieses
70
70
  draw unit: unit, multiple: multiple do
71
71
  repeat do
72
72
  param.vlines.each do |line|
73
- vline line.tag, style: line.style
73
+ vline(*line.tags, style: line.style)
74
74
  right line.step
75
75
  end
76
76
  end
@@ -86,7 +86,7 @@ module Dieses
86
86
  repeat do
87
87
  param.clines.each do |slant|
88
88
  repeat do
89
- cline slant.tag, angle: slant.angle, style: slant.style
89
+ cline(*slant.tags, angle: slant.angle, style: slant.style)
90
90
  cross
91
91
  end
92
92
  end
@@ -43,34 +43,22 @@ module Dieses
43
43
 
44
44
  module Bundle
45
45
  def quartet
46
- hline :ascender, after: proc { height },
47
- style: Style.(stroke: 'blue', 'stroke-width': '0.2')
48
- hline :waist, after: proc { x_height },
49
- style: Style.(stroke: 'grey', 'stroke-width': '0.1', 'stroke-dasharray': '2, 2')
50
- hline :base, after: proc { height },
51
- style: Style.(stroke: 'red', 'stroke-width': '0.1', 'stroke-dasharray': '2, 2')
52
- hline :descender, after: proc { gap },
53
- style: Style.(stroke: 'blue', 'stroke-width': '0.2')
46
+ hline :ascender, :thick, after: proc { height }
47
+ hline :waist, :altcolor, after: proc { x_height }
48
+ hline :base, after: proc { height }
49
+ hline :descender, :thick, after: proc { gap }
54
50
  end
55
51
 
56
- # rubocop:disable Metrics/MethodLength
57
52
  # codebeat:disable[ABC]
58
53
  def sextet
59
- hline :ascender2, after: proc { height },
60
- style: Style.(stroke: 'blue', 'stroke-width': '0.2')
61
- hline :ascender1, after: proc { height },
62
- style: Style.(stroke: 'grey', 'stroke-width': '0.1', 'stroke-dasharray': '2, 2')
63
- hline :waist, after: proc { x_height },
64
- style: Style.(stroke: 'grey', 'stroke-width': '0.1')
65
- hline :base, after: proc { height },
66
- style: Style.(stroke: 'red', 'stroke-width': '0.1')
67
- hline :descender1, after: proc { height },
68
- style: Style.(stroke: 'grey', 'stroke-width': '0.1', 'stroke-dasharray': '2, 2')
69
- hline :descender2, after: proc { gap },
70
- style: Style.(stroke: 'blue', 'stroke-width': '0.2')
54
+ hline :ascender2, :thick, after: proc { height }
55
+ hline :ascender1, :dashed, after: proc { height }
56
+ hline :waist, :altcolor, after: proc { x_height }
57
+ hline :base, after: proc { height }
58
+ hline :descender1, :dashed, after: proc { height }
59
+ hline :descender2, :thick, after: proc { gap }
71
60
  end
72
61
  # codebeat:enable[ABC]
73
- # rubocop:enable Metrics/MethodLength
74
62
  end
75
63
 
76
64
  def included(base)
@@ -10,7 +10,7 @@ module Dieses
10
10
  draw unit: Undefined.default(unit, param.unit), multiple: Undefined.default(multiple, param.multiple) do
11
11
  repeat do
12
12
  repeat do
13
- square :square, width: multiple, style: Style.(stroke: 'blue', 'stroke-width': '0.2', fill: 'none')
13
+ square :square, width: multiple
14
14
  right multiple
15
15
  end
16
16
  down multiple
@@ -79,40 +79,37 @@ module Dieses
79
79
  Offsite = Class.new StopIteration
80
80
 
81
81
  module Elements
82
- def hline(tag = Undefined, length: Undefined, style: Undefined)
82
+ def hline(*tags, length: Undefined, style: Undefined)
83
83
  length = Undefined.equal?(length) ? perfect.width : ruler.measure(length)
84
- add Geometry::Line.new(pos, pos.translate(x: length)), tag, style
84
+ add Geometry::Line.new(pos, pos.translate(x: length)), tags, style
85
85
  end
86
86
 
87
- def vline(tag = Undefined, length: Undefined, style: Undefined)
87
+ def vline(*tags, length: Undefined, style: Undefined)
88
88
  length = Undefined.equal?(length) ? perfect.height : ruler.measure(length)
89
- add Geometry::Line.new(pos, pos.translate(y: length)), tag, style
89
+ add Geometry::Line.new(pos, pos.translate(y: length)), tags, style
90
90
  end
91
91
 
92
- def cline(tag = Undefined, angle:, style: Undefined)
93
- add perfect.intersect(Geometry::Equation.slant_from_direction(point: pos, angle: -angle)), tag, style
92
+ def cline(*tags, angle:, style: Undefined)
93
+ add perfect.intersect(Geometry::Equation.slant_from_direction(point: pos, angle: -angle)), tags, style
94
94
  end
95
95
 
96
- def rect(tag = Undefined, width:, height:, style: Undefined)
96
+ def rect(*tags, width:, height:, style: Undefined)
97
97
  width, height = ruler.measure(width), ruler.measure(height)
98
- add Geometry::Rect.new(width, height, position: pos), tag, style
98
+ style = { fill: 'none' }.merge Undefined.default(style, EMPTY_HASH).to_h
99
+ add Geometry::Rect.new(width, height, position: pos), tags, style
99
100
  end
100
101
 
101
- def square(tag = Undefined, width:, style: Undefined)
102
- rect(tag, width: width, height: width, style: style)
102
+ def square(*tags, width:, style: Undefined)
103
+ rect(tags, width: width, height: width, style: style)
103
104
  end
104
105
 
105
106
  private
106
107
 
107
- BASE_STYLE = { stroke: 'black', 'stroke-width': '0.1' }.freeze
108
-
109
- def add(element, tag, style)
108
+ def add(element, tags, style)
110
109
  raise Offsite unless element && perfect.cover?(element)
111
110
 
112
- tag = Undefined.default(tag, caller_locations(1, 1).first.label.to_sym)
113
-
114
111
  element.tap do
115
- buffer << element.classify(tag, **BASE_STYLE.merge(Undefined.default(style, EMPTY_HASH).to_h))
112
+ buffer << element.classify(tags, **Undefined.default(style, EMPTY_HASH).to_h)
116
113
  end
117
114
  end
118
115
 
@@ -8,8 +8,8 @@ module Dieses
8
8
 
9
9
  include Mixins::Scribes[:sextet].with unit: [5, 7], ratio: [3/2r, 2/1r]
10
10
 
11
- cline :slant, angle: 55.0, style: Style.(stroke: 'blue', 'stroke-width': 0.1)
12
- cline :connective, angle: 50.0, style: Style.(stroke: 'blue', 'stroke-width': 0.07, 'stroke-dasharray': '2, 2')
11
+ cline :slant, :thin, angle: 55.0
12
+ cline :connective, :thin, :dashed, angle: 50.0
13
13
 
14
14
  def call
15
15
  scribes
@@ -8,7 +8,7 @@ module Dieses
8
8
 
9
9
  include Mixins::Scribes[:quartet].with unit: [5, 7, 10]
10
10
 
11
- cline :slant, angle: 60.0, style: Style.(stroke: 'blue', 'stroke-width': 0.05)
11
+ cline :slant, :thin, angle: 60.0
12
12
 
13
13
  def call
14
14
  scribes
@@ -14,8 +14,8 @@ module Dieses
14
14
  self.desc = "#{square} squares with #{unit} mm unit"
15
15
  end
16
16
 
17
- hline :hline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
18
- vline :vline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
17
+ hline :hline
18
+ vline :vline
19
19
 
20
20
  def call
21
21
  lines multiple: param.square
@@ -8,7 +8,7 @@ module Dieses
8
8
 
9
9
  include Mixins::Scribes[:quartet].with unit: [5, 7, 10]
10
10
 
11
- cline :slant, angle: 81.0, style: Style.(stroke: 'blue', 'stroke-width': 0.05)
11
+ cline :slant, :thin, angle: 81.0
12
12
 
13
13
  def call
14
14
  scribes
@@ -14,11 +14,11 @@ module Dieses
14
14
  self.desc = "#{square} squares with #{unit} mm unit"
15
15
  end
16
16
 
17
- hline :hline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
18
- vline :vline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
17
+ hline :hline
18
+ vline :vline
19
19
 
20
- cline :slant, angle: 52.0, style: Style.(stroke: 'blue', 'stroke-width': 0.1)
21
- cline :connective, angle: 30.0, style: Style.(stroke: 'blue', 'stroke-width': 0.07, 'stroke-dasharray': '2, 2')
20
+ cline :slant, :thin, angle: 52.0
21
+ cline :connective, :thin, :dashed, angle: 30.0
22
22
 
23
23
  def call
24
24
  lines multiple: param.square
@@ -13,7 +13,7 @@ module Dieses
13
13
  self.desc = "#{unit} mm unit"
14
14
  end
15
15
 
16
- hline :hline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
16
+ hline :hline
17
17
 
18
18
  def call
19
19
  lines
@@ -8,7 +8,7 @@ module Dieses
8
8
 
9
9
  include Mixins::Scribes[:quartet].with unit: [5, 7, 10]
10
10
 
11
- vline :vline, style: Style.(stroke: 'blue', 'stroke-width': '0.05')
11
+ vline :vline
12
12
 
13
13
  def call
14
14
  scribes
@@ -13,8 +13,8 @@ module Dieses
13
13
  self.desc = "#{unit} mm unit"
14
14
  end
15
15
 
16
- hline :hline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
17
- vline :vline, style: Style.(stroke: 'blue', 'stroke-width': '0.1')
16
+ hline :hline
17
+ vline :vline
18
18
 
19
19
  def call
20
20
  lines
@@ -8,8 +8,8 @@ module Dieses
8
8
 
9
9
  include Mixins::Scribes[:sextet].with unit: [5, 7], ratio: [3/2r, 2/1r]
10
10
 
11
- cline :slant, angle: 52.0, style: Style.(stroke: 'blue', 'stroke-width': 0.1)
12
- cline :connective, angle: 30.0, style: Style.(stroke: 'blue', 'stroke-width': 0.07, 'stroke-dasharray': '2, 2')
11
+ cline :slant, :thin, angle: 52.0
12
+ cline :connective, :thin, :dashed, angle: 30.0
13
13
 
14
14
  def call
15
15
  scribes
@@ -24,7 +24,7 @@ module Dieses
24
24
  draw unit: param.unit do
25
25
  repeat row do
26
26
  repeat col do
27
- rect :rect, width: width, height: height, style: Style.(stroke: 'blue', 'stroke-width': '0.2', fill: 'none') # rubocop:disable Layout/LineLength
27
+ rect :rect, width: width, height: height
28
28
  right(width + 1)
29
29
  end
30
30
  down(height + 1)
@@ -21,7 +21,7 @@ module Dieses
21
21
 
22
22
  def classify(*tags, **kwargs)
23
23
  existing_class = attributes[:class] || Set.new
24
- attr(**kwargs, tags: existing_class.add(tags))
24
+ attr(**kwargs, class: existing_class.add(tags))
25
25
  end
26
26
 
27
27
  def to_svg
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dieses
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dieses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recai Oktaş
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.2.5
222
+ rubygems_version: 3.2.26
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Guide sheets generator for penmanship, calligraphy, lettering, and sketching