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.
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rbs_inline: enabled
4
+
5
+ module Glamour
6
+ class StyleDefinition
7
+ # @rbs @attributes: Hash[Symbol, untyped]
8
+ # @rbs return: void
9
+ def initialize(&)
10
+ @attributes = {}
11
+ instance_eval(&) if block_given?
12
+ end
13
+
14
+ # @rbs return: Hash[Symbol, untyped]
15
+ def to_h
16
+ @attributes
17
+ end
18
+
19
+ private
20
+
21
+ # @rbs name: Symbol -- the attribute name
22
+ # @rbs value: untyped -- the attribute value
23
+ # @rbs return: untyped
24
+ def method_missing(name, value = nil, &)
25
+ @attributes[name] = if block_given?
26
+ StyleDefinition.new(&).to_h
27
+ else
28
+ value
29
+ end
30
+ end
31
+
32
+ # @rbs _name: Symbol
33
+ # @rbs _include_private: bool
34
+ # @rbs return: true
35
+ def respond_to_missing?(_name, _include_private = false)
36
+ true
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rbs_inline: enabled
4
+
3
5
  module Glamour
4
- VERSION = "0.0.1"
6
+ # @rbs const VERSION: String
7
+ VERSION = "0.1.0"
5
8
  end
data/lib/glamour.rb CHANGED
@@ -1,8 +1,76 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rbs_inline: enabled
4
+
5
+ require "json"
3
6
  require_relative "glamour/version"
7
+ require_relative "glamour/glamour"
8
+ require_relative "glamour/renderer"
9
+ require_relative "glamour/style"
4
10
 
5
11
  module Glamour
6
- class Error < StandardError; end
7
- # Your code goes here...
12
+ class << self
13
+ alias render_native render
14
+
15
+ # @rbs markdown: String -- the markdown content to render
16
+ # @rbs style: String | singleton(Glamour::Style) -- style name or Style subclass
17
+ # @rbs width: Integer -- optional word wrap width
18
+ # @rbs return: String -- rendered output with ANSI escape codes
19
+ def render(markdown, style: "auto", width: 0, **)
20
+ if style_class?(style)
21
+ render_with_style_class(markdown, style, width: width, **)
22
+ else
23
+ render_native(markdown, style: style, width: width, **)
24
+ end
25
+ end
26
+
27
+ # @rbs markdown: String -- the markdown content to render
28
+ # @rbs style: Hash[Symbol, untyped] | String | singleton(Glamour::Style) -- style definition
29
+ # @rbs width: Integer -- optional word wrap width
30
+ # @rbs return: String -- rendered output with ANSI escape codes
31
+ def render_with_style(markdown, style, width: 0)
32
+ json_style = style_to_json(style)
33
+
34
+ render_with_json(markdown, json_style, width: width)
35
+ end
36
+
37
+ private
38
+
39
+ # @rbs style: untyped
40
+ # @rbs return: bool
41
+ def style_class?(style)
42
+ style.is_a?(Class) && style.respond_to?(:glamour_style?) && style.glamour_style?
43
+ end
44
+
45
+ # @rbs style: Hash[Symbol, untyped] | String | singleton(Glamour::Style)
46
+ # @rbs return: String
47
+ def style_to_json(style)
48
+ case style
49
+ when Class
50
+ raise ArgumentError, "Expected Glamour::Style subclass, got #{style}" unless style_class?(style)
51
+
52
+ style.to_json
53
+ when Hash
54
+ JSON.generate(style)
55
+ when String
56
+ style
57
+ else
58
+ raise ArgumentError, "Expected Style class, Hash, or JSON string, got #{style.class}"
59
+ end
60
+ end
61
+
62
+ # @rbs markdown: String -- the markdown content to render
63
+ # @rbs style_class: singleton(Glamour::Style) -- the Style subclass
64
+ # @rbs width: Integer -- optional word wrap width
65
+ # @rbs return: String -- rendered output with ANSI escape codes
66
+ def render_with_style_class(markdown, style_class, width: 0, **_options)
67
+ styles = style_class.to_h
68
+
69
+ if styles.empty?
70
+ render_native(markdown, style: "auto", width: width)
71
+ else
72
+ render_with_json(markdown, JSON.generate(styles), width: width)
73
+ end
74
+ end
75
+ end
8
76
  end
metadata CHANGED
@@ -1,36 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glamour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: Stylesheet-based markdown rendering for your CLI apps. Integrate Charm's
13
- glamour with the RubyGems infrastructure.
12
+ description: Ruby wrapper for Charm's glamour stylesheet-based markdown rendering
13
+ for Ruby CLI apps.
14
14
  email:
15
15
  - marco.roth@intergga.ch
16
16
  executables: []
17
- extensions: []
17
+ extensions:
18
+ - ext/glamour/extconf.rb
18
19
  extra_rdoc_files: []
19
20
  files:
20
- - CHANGELOG.md
21
- - CODE_OF_CONDUCT.md
21
+ - LICENSE.txt
22
22
  - README.md
23
- - Rakefile
23
+ - ext/glamour/extconf.rb
24
+ - ext/glamour/extension.c
25
+ - glamour.gemspec
26
+ - go/glamour.go
27
+ - go/go.mod
28
+ - go/go.sum
24
29
  - lib/glamour.rb
30
+ - lib/glamour/renderer.rb
31
+ - lib/glamour/style.rb
32
+ - lib/glamour/style_definition.rb
25
33
  - lib/glamour/version.rb
26
- - sig/glamour.rbs
27
- homepage: https://github.com/marcoroth/glamour
34
+ homepage: https://github.com/marcoroth/glamour-ruby
28
35
  licenses:
29
36
  - MIT
30
37
  metadata:
31
- homepage_uri: https://github.com/marcoroth/glamour
32
- source_code_uri: https://github.com/marcoroth/glamour
33
- changelog_uri: https://github.com/marcoroth/glamour/blob/main/CHANGELOG.md
38
+ homepage_uri: https://github.com/marcoroth/glamour-ruby
39
+ source_code_uri: https://github.com/marcoroth/glamour-ruby
40
+ changelog_uri: https://github.com/marcoroth/glamour-ruby/releases
34
41
  rubygems_mfa_required: 'true'
35
42
  rdoc_options: []
36
43
  require_paths:
@@ -48,5 +55,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
55
  requirements: []
49
56
  rubygems_version: 3.6.9
50
57
  specification_version: 4
51
- summary: Ruby wrapper for Charm's glamour CLI tool.
58
+ summary: Ruby wrapper for Charm's glamour stylesheet-based markdown rendering for
59
+ Ruby CLI apps.
52
60
  test_files: []
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2025-12-07
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,132 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, caste, color, religion, or sexual
10
- identity and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the overall
26
- community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or advances of
31
- any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email address,
35
- without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official email address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- [INSERT CONTACT METHOD].
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series of
86
- actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or permanent
93
- ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within the
113
- community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.1, available at
119
- [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
-
121
- Community Impact Guidelines were inspired by
122
- [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
-
124
- For answers to common questions about this code of conduct, see the FAQ at
125
- [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
- [https://www.contributor-covenant.org/translations][translations].
127
-
128
- [homepage]: https://www.contributor-covenant.org
129
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
- [Mozilla CoC]: https://github.com/mozilla/diversity
131
- [FAQ]: https://www.contributor-covenant.org/faq
132
- [translations]: https://www.contributor-covenant.org/translations
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
5
-
6
- Minitest::TestTask.create
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[test rubocop]
data/sig/glamour.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Glamour
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end