glamour 0.0.1 → 0.1.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: 2d0ecf8fcc767052fa79a80770da871d02c62fd62bc505a56ec614ccc565e3c3
4
- data.tar.gz: 7e1e2eb1053f154da64ede7c46ced5197b6c96f19399339b2377c285da449a11
3
+ metadata.gz: 3beabca10dea479df451bf2fa5b90cd7105b481f083ba2af84e2a5205d10e269
4
+ data.tar.gz: d5671fbf5384cdf925a6596baf3784d20e6e79236fb8d901e678cd488fcf5573
5
5
  SHA512:
6
- metadata.gz: a1a913819e3ecf1203e991f8ad418d2df641ee44fca60cf92e64156f3a955e566ac703cac217e3afc0530c1f6785641dc7a3a57320c4b0b30d3ee6d07bfafd24
7
- data.tar.gz: bfa13eee909f6953ff86752a0b27f7d4700bdca4ac4b8d9a490080c6a4915a5456c48e2a0e0023cff7901500838701e7e2bb29bf6e222833641f6128bd21f580
6
+ metadata.gz: e89304cd6bdd6ecffc8d389719ed4da14c41c919b8c5c1ac4eab5bcc217c1cc68f8fc3c14d26c58c9c57cbcb59c4f0096ef8a53ec9a15b5e7907d20fc67b48a5
7
+ data.tar.gz: 756f7149b87f9283f3f5cf984e26b4b7d682eff1b00f1715943df1f97a3ce382c689d7765631ab0163541a8ff49e32a566e8c364b2752ae140019f496b58f0d5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Marco Roth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,39 +1,306 @@
1
- # Glamour
1
+ <div align="center">
2
+ <h1>Glamour</h1>
3
+ <h4>Stylesheet-based Markdown Rendering for Ruby CLI Apps</h4>
2
4
 
3
- TODO: Delete this and the text below, and describe your gem
5
+ <p>
6
+ <a href="https://rubygems.org/gems/glamour"><img alt="Gem Version" src="https://img.shields.io/gem/v/glamour"></a>
7
+ <a href="https://github.com/marcoroth/glamour-ruby/blob/main/LICENSE.txt"><img alt="License" src="https://img.shields.io/github/license/marcoroth/glamour-ruby"></a>
8
+ </p>
4
9
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/glamour`. To experiment with that code, run `bin/console` for an interactive prompt.
10
+ <p>Ruby bindings for <a href="https://github.com/charmbracelet/glamour">charmbracelet/glamour</a>.<br/>Render markdown documents with beautiful styling on ANSI-compatible terminals.</p>
11
+ </div>
6
12
 
7
13
  ## Installation
8
14
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
15
+ **Add to your Gemfile:**
10
16
 
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```ruby
18
+ gem "glamour"
15
19
  ```
16
20
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ **Or install directly:**
18
22
 
19
23
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ gem install glamour
21
25
  ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ### Basic Rendering
30
+
31
+ **Render markdown with auto-detected style:**
32
+
33
+ ```ruby
34
+ require "glamour"
35
+
36
+ puts Glamour.render("# Hello World")
37
+ ```
38
+
39
+ **Render with a specific style:**
40
+
41
+ ```ruby
42
+ puts Glamour.render("# Hello", style: "dark")
43
+ puts Glamour.render("# Hello", style: "light")
44
+ puts Glamour.render("# Hello", style: "dracula")
45
+ puts Glamour.render("# Hello", style: "notty")
46
+ ```
47
+
48
+ **Render with word wrap:**
49
+
50
+ ```ruby
51
+ puts Glamour.render(long_markdown, width: 80)
52
+ ```
53
+
54
+ ### Render Options
55
+
56
+ | Option | Description |
57
+ |--------|-------------|
58
+ | `style` | `"auto"`, `"dark"`, `"light"`, `"notty"`, `"dracula"` |
59
+ | `width` | Word wrap width |
60
+ | `emoji` | Enable emoji rendering (`:wave:` → 👋) |
61
+ | `preserve_newlines` | Preserve newlines in output |
62
+ | `base_url` | Base URL for relative links |
63
+ | `color_profile` | `:auto`, `:true_color`, `:ansi256`, `:ansi`, `:ascii` |
64
+
65
+ **Example with all options:**
66
+
67
+ ```ruby
68
+ Glamour.render(markdown,
69
+ style: "dark",
70
+ width: 80,
71
+ emoji: true,
72
+ preserve_newlines: true,
73
+ base_url: "https://example.com",
74
+ color_profile: :true_color
75
+ )
76
+ ```
77
+
78
+ ### Custom Styles with Hash
79
+
80
+ **Define a custom style:**
81
+
82
+ ```ruby
83
+ custom_style = {
84
+ heading: { bold: true, color: "212" },
85
+ strong: { bold: true, color: "196" },
86
+ emph: { italic: true, color: "226" },
87
+ code: { color: "203", background_color: "236" }
88
+ }
89
+ ```
90
+
91
+ **Render with the custom style:**
92
+
93
+ ```ruby
94
+ Glamour.render_with_style("# Hello **World**", custom_style)
95
+ ```
96
+
97
+ **With width option:**
98
+
99
+ ```ruby
100
+ Glamour.render_with_style("# Hello", custom_style, width: 60)
101
+ ```
102
+
103
+ ### Style DSL
104
+
105
+ **Define reusable styles using a Ruby DSL:**
106
+
107
+ ```ruby
108
+ class MyStyle < Glamour::Style
109
+ style :heading do
110
+ bold true
111
+ color "212"
112
+ end
113
+
114
+ style :h1 do
115
+ prefix "# "
116
+ color "99"
117
+ bold true
118
+ end
119
+
120
+ style :strong do
121
+ bold true
122
+ color "196"
123
+ end
124
+
125
+ style :emph do
126
+ italic true
127
+ color "226"
128
+ end
129
+
130
+ style :code do
131
+ color "203"
132
+ background_color "236"
133
+ end
134
+
135
+ style :document do
136
+ margin 2
137
+ end
138
+ end
139
+ ```
140
+
141
+ **Use the style class directly:**
142
+
143
+ ```ruby
144
+ MyStyle.render("# Hello **World**")
145
+ MyStyle.render("# Hello", width: 80)
146
+ ```
147
+
148
+ **Or pass to Glamour.render:**
149
+
150
+ ```ruby
151
+ Glamour.render("# Hello", style: MyStyle)
152
+ ```
153
+
154
+ ### Reusable Renderer
155
+
156
+ **Create a renderer with preset options:**
157
+
158
+ ```ruby
159
+ renderer = Glamour::Renderer.new(
160
+ style: "dark",
161
+ width: 80,
162
+ emoji: true
163
+ )
164
+ ```
165
+
166
+ **Render multiple documents:**
167
+
168
+ ```ruby
169
+ puts renderer.render("# Hello :wave:")
170
+ puts renderer.render("# Another document")
171
+ ```
172
+
173
+ **With a Style class:**
174
+
175
+ ```ruby
176
+ renderer = Glamour::Renderer.new(style: MyStyle, width: 60)
177
+ puts renderer.render("# Styled output")
178
+ ```
179
+
180
+ ## Available Style Elements
181
+
182
+ ### Block Elements
183
+
184
+ | Element | Description |
185
+ |---------|-------------|
186
+ | `document` | Root document wrapper |
187
+ | `paragraph` | Text paragraphs |
188
+ | `heading` | Base heading style (h1-h6 inherit from this) |
189
+ | `h1` - `h6` | Individual heading levels |
190
+ | `block_quote` | Block quotations |
191
+ | `code_block` | Fenced code blocks |
192
+ | `list` | List containers |
193
+ | `item` | List items (bullets) |
194
+ | `enumeration` | Numbered list items |
195
+ | `table` | Markdown tables |
196
+ | `hr` | Horizontal rules |
197
+
198
+ ### Inline Elements
199
+
200
+ | Element | Description |
201
+ |---------|-------------|
202
+ | `text` | Base text styling |
203
+ | `strong` | Bold text (`**bold**`) |
204
+ | `emph` | Italic text (`*italic*`) |
205
+ | `strikethrough` | Strikethrough text |
206
+ | `code` | Inline code (`` `code` ``) |
207
+ | `link` | Link elements |
208
+ | `link_text` | Link text display |
209
+ | `image` | Image references |
210
+
211
+ ## Style Properties
212
+
213
+ **Text decoration:**
214
+
215
+ ```ruby
216
+ bold true
217
+ italic true
218
+ underline true
219
+ crossed_out true
220
+ faint true
221
+ inverse true
222
+ overlined true
223
+ ```
224
+
225
+ **Colors (ANSI 256 color codes):**
226
+
227
+ ```ruby
228
+ color "212"
229
+ background_color "236"
230
+ ```
231
+
232
+ **Spacing:**
233
+
234
+ ```ruby
235
+ margin 2
236
+ indent 1
237
+ indent_token " "
238
+ level_indent 2
239
+ ```
240
+
241
+ **Prefix/suffix:**
242
+
243
+ ```ruby
244
+ prefix "# "
245
+ suffix ""
246
+ block_prefix ""
247
+ block_suffix "\n"
248
+ ```
249
+
250
+ ## Built-in Styles
251
+
252
+ - `"auto"` - Auto-detect dark/light terminal
253
+ - `"dark"` - Dark terminal theme
254
+ - `"light"` - Light terminal theme
255
+ - `"notty"` - No colors (for non-TTY output)
256
+ - `"dracula"` - Dracula color scheme
257
+
258
+ ## Version Info
259
+
260
+ ```ruby
261
+ puts Glamour.version
262
+ ```
26
263
 
27
264
  ## Development
28
265
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
266
+ **Requirements:**
267
+ - Go 1.23+
268
+ - Ruby 3.2+
30
269
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
270
+ **Install dependencies:**
271
+
272
+ ```bash
273
+ bundle install
274
+ ```
275
+
276
+ **Build the Go library and compile the extension:**
277
+
278
+ ```bash
279
+ bundle exec rake compile
280
+ ```
281
+
282
+ **Run tests:**
283
+
284
+ ```bash
285
+ bundle exec rake test
286
+ ```
287
+
288
+ **Run demos:**
289
+
290
+ ```bash
291
+ ./demo/basic
292
+ ./demo/styles
293
+ ./demo/style_dsl
294
+ ```
32
295
 
33
296
  ## Contributing
34
297
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/glamour. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcoroth/glamour/blob/main/CODE_OF_CONDUCT.md).
298
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/glamour-ruby.
299
+
300
+ ## License
301
+
302
+ The gem is available as open source under the terms of the MIT License.
36
303
 
37
- ## Code of Conduct
304
+ ## Acknowledgments
38
305
 
39
- Everyone interacting in the Glamour project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/glamour/blob/main/CODE_OF_CONDUCT.md).
306
+ This gem wraps [charmbracelet/glamour](https://github.com/charmbracelet/glamour), part of the excellent [Charm](https://charm.sh) ecosystem.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ extension_name = "glamour"
6
+
7
+ def detect_platform
8
+ cpu = RbConfig::CONFIG["host_cpu"]
9
+ os = RbConfig::CONFIG["host_os"]
10
+
11
+ arch = case cpu
12
+ when /aarch64|arm64/ then "arm64"
13
+ when /x86_64|amd64/ then "amd64"
14
+ when /arm/ then "arm"
15
+ when /i[3-6]86/ then "386"
16
+ else cpu
17
+ end
18
+
19
+ goos = case os
20
+ when /darwin/ then "darwin"
21
+ when /mswin|mingw/ then "windows"
22
+ else "linux"
23
+ end
24
+
25
+ "#{goos}_#{arch}"
26
+ end
27
+
28
+ platform = detect_platform
29
+ go_lib_dir = File.expand_path("../../go/build/#{platform}", __dir__)
30
+
31
+ puts "Looking for Go library in: #{go_lib_dir}"
32
+
33
+ unless File.exist?(File.join(go_lib_dir, "libglamour.a"))
34
+ abort <<~ERROR
35
+ Could not find libglamour.a for platform #{platform}
36
+
37
+ Please build the Go archive first:
38
+ cd go && go build -buildmode=c-archive -o build/#{platform}/libglamour.a .
39
+
40
+ Or run:
41
+ bundle exec rake go:build
42
+ ERROR
43
+ end
44
+
45
+ $LDFLAGS << " -L#{go_lib_dir}"
46
+ $INCFLAGS << " -I#{go_lib_dir}"
47
+
48
+ $LOCAL_LIBS << " #{go_lib_dir}/libglamour.a"
49
+
50
+ case RbConfig::CONFIG["host_os"]
51
+ when /darwin/
52
+ $LDFLAGS << " -framework CoreFoundation -framework Security -framework SystemConfiguration"
53
+ $LDFLAGS << " -lresolv"
54
+ when /linux/
55
+ $LDFLAGS << " -lpthread -lm -ldl"
56
+ $LDFLAGS << " -lresolv" if find_library("resolv", "res_query")
57
+ end
58
+
59
+ create_makefile("#{extension_name}/#{extension_name}")