chamomile-flourish 0.1.1 → 0.2.0

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: 99ff8353639abd9d1ebbdb7bf6671a6ba65a7f1a34ccf7065357dcc9e058d133
4
- data.tar.gz: 5cae6fc2d9f85cf20b6887322265fb5a493baa31dc27d8bd65b06965c45716d2
3
+ metadata.gz: 73bccda63b64cd67d97ef4b8ff7c098e4098cce08426894b8a717df63d640dfb
4
+ data.tar.gz: d26ed006acffbf7a6863b055ed69543811c83450fbf2ac5b27a92b7f06ed1d31
5
5
  SHA512:
6
- metadata.gz: 76584a587427f401062a13ed8f36de308158f32a2ad4fddeee98cf39cb4fd9a543b51f2a59dd0bcad839fd77298ad16828eeb89a791690ee0e080734cdfa5e83
7
- data.tar.gz: 7859519fecc20af8437f5a8f11972d883b7aa19a382dedb6929e7bd974a1627ba62d42a1abd2860dce08d67a702bae38fae3a44aec26db89819f475ed045d800
6
+ metadata.gz: 93ba8923e8bf8303cf5ec49a909917a308df7cb1352597c847bb1e305aab0bb406c8db8a4fdd53758eda8b674b082eef028cc65ce4acba1b7be50832cccfb819
7
+ data.tar.gz: eb13351362d89be36d4876c81bf4983f0f26a72d8d06bb2314fb7dc7bf92cf2129cd0aaaa594f996e8ed0109befb1e74bab75d89a11d284ed82d1c3eb819d2b3
@@ -170,13 +170,13 @@ module Flourish
170
170
 
171
171
  def align(*positions)
172
172
  copy = dup
173
- copy.set_prop!(:align_horizontal, positions[0]) if positions.length >= 1
174
- copy.set_prop!(:align_vertical, positions[1]) if positions.length >= 2
173
+ copy.set_prop!(:align_horizontal, Flourish.resolve_position(positions[0])) if positions.length >= 1
174
+ copy.set_prop!(:align_vertical, Flourish.resolve_position(positions[1])) if positions.length >= 2
175
175
  copy
176
176
  end
177
177
 
178
- def align_horizontal(pos) = assign_prop(:align_horizontal, pos)
179
- def align_vertical(pos) = assign_prop(:align_vertical, pos)
178
+ def align_horizontal(pos) = assign_prop(:align_horizontal, Flourish.resolve_position(pos))
179
+ def align_vertical(pos) = assign_prop(:align_vertical, Flourish.resolve_position(pos))
180
180
 
181
181
  # --- Whitespace options ---
182
182
 
@@ -359,8 +359,8 @@ module Flourish
359
359
  def effective_margin_bottom = @margin_bottom || 0
360
360
  def effective_margin_left = @margin_left || 0
361
361
  def effective_border_style = @border_style
362
- def effective_align_horizontal = @align_horizontal || Flourish::LEFT
363
- def effective_align_vertical = @align_vertical || Flourish::TOP
362
+ def effective_align_horizontal = @align_horizontal || 0.0
363
+ def effective_align_vertical = @align_vertical || 0.0
364
364
 
365
365
  def compute_content_width
366
366
  w = effective_width
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flourish
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/flourish.rb CHANGED
@@ -12,13 +12,22 @@ require_relative "flourish/place"
12
12
  require_relative "flourish/style"
13
13
 
14
14
  module Flourish
15
- # Position constants
15
+ # Position constants (kept for backward compat)
16
16
  TOP = 0.0
17
17
  LEFT = 0.0
18
18
  CENTER = 0.5
19
19
  BOTTOM = 1.0
20
20
  RIGHT = 1.0
21
21
 
22
+ # Symbol-to-float position map
23
+ POSITION_MAP = {
24
+ top: 0.0,
25
+ left: 0.0,
26
+ center: 0.5,
27
+ bottom: 1.0,
28
+ right: 1.0,
29
+ }.freeze
30
+
22
31
  class << self
23
32
  def width(str)
24
33
  ANSI.printable_width(str)
@@ -32,24 +41,64 @@ module Flourish
32
41
  ANSI.size(str)
33
42
  end
34
43
 
35
- def join_horizontal(position, *strs)
36
- Join.horizontal(position, *strs)
44
+ # New primary API — accepts array or block, keyword align
45
+ def horizontal(strs = nil, align: :top, &block)
46
+ strs = block.call if block && strs.nil?
47
+ strs = Array(strs)
48
+ Join.horizontal(resolve_position(align), *strs)
37
49
  end
38
50
 
39
- def join_vertical(position, *strs)
40
- Join.vertical(position, *strs)
51
+ # New primary API — accepts array or block, keyword align
52
+ def vertical(strs = nil, align: :left, &block)
53
+ strs = block.call if block && strs.nil?
54
+ strs = Array(strs)
55
+ Join.vertical(resolve_position(align), *strs)
41
56
  end
42
57
 
43
- def place(width, height, h_pos, v_pos, str)
44
- Place.place(width, height, h_pos, v_pos, str)
58
+ # New primary API — content first, keyword args
59
+ # Also supports old positional form for backward compat
60
+ def place(first, second = nil, third = nil, fourth = nil, fifth = nil,
61
+ width: nil, height: nil, align: :left, valign: :top, content: nil)
62
+ if fifth
63
+ # Old 5-arg form: place(width, height, h_pos, v_pos, str)
64
+ Place.place(first, second, resolve_position(third), resolve_position(fourth), fifth.to_s)
65
+ else
66
+ # New keyword form: place(content, width:, height:, align:, valign:)
67
+ content = (content || first).to_s
68
+ Place.place(width || 80, height || 24,
69
+ resolve_position(align), resolve_position(valign), content)
70
+ end
71
+ end
72
+
73
+ # Old API — kept for backward compat
74
+ def join_horizontal(position, *strs)
75
+ Join.horizontal(resolve_position(position), *strs)
76
+ end
77
+
78
+ # Old API — kept for backward compat
79
+ def join_vertical(position, *strs)
80
+ Join.vertical(resolve_position(position), *strs)
45
81
  end
46
82
 
47
83
  def place_horizontal(width, pos, str)
48
- Place.place_horizontal(width, pos, str)
84
+ Place.place_horizontal(width, resolve_position(pos), str)
49
85
  end
50
86
 
51
87
  def place_vertical(height, pos, str)
52
- Place.place_vertical(height, pos, str)
88
+ Place.place_vertical(height, resolve_position(pos), str)
89
+ end
90
+
91
+ # Convert symbol positions to float values.
92
+ # Accepts symbols (:top, :left, :center, :bottom, :right) or floats.
93
+ def resolve_position(val)
94
+ case val
95
+ when Symbol
96
+ POSITION_MAP.fetch(val) { raise ArgumentError, "Unknown position: #{val.inspect}" }
97
+ when Numeric
98
+ val.to_f
99
+ else
100
+ raise ArgumentError, "Expected a Symbol or Numeric position, got #{val.inspect}"
101
+ end
53
102
  end
54
103
  end
55
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chamomile-flourish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Killilea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-10 00:00:00.000000000 Z
11
+ date: 2026-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec