grokdown 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +57 -47
- data/README.md +106 -19
- data/Rakefile +7 -7
- data/exe/grokdown +21 -0
- data/lib/grokdown/composing.rb +21 -0
- data/lib/grokdown/creating.rb +21 -34
- data/lib/grokdown/document.rb +10 -9
- data/lib/grokdown/matching.rb +7 -9
- data/lib/grokdown/never_composes.rb +13 -0
- data/lib/grokdown/version.rb +3 -1
- data/lib/grokdown.rb +12 -2
- data/sig/grokdown.rbs +4 -0
- metadata +23 -74
- data/.gitignore +0 -9
- data/Gemfile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/grokdown.gemspec +0 -31
- data/lib/grokdown/consuming.rb +0 -35
- data/lib/grokdown/never_consumes.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac8a98fe8b785069748b8188029679769d84f1a4b7b8cf92abe5168669e0f5dd
|
4
|
+
data.tar.gz: e447bf05e89b2726b9715984d1e74fbb756c00400173efda99da59cedcc53bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddbc26e585b14064b760417a7b3108f385f7df479497fa2753ed22b24a613f8f9175427b540a41c217b85a5b0288782465de95076cc7d6b6ad42cd3f98818dd3
|
7
|
+
data.tar.gz: 18ffe9aa81977fe8c99c016ad95cd6bb77502ac85cc88c3f22848db0c945e43331af8b91dae20ee55fe6c4faa3e5fcdebb83474bf8ca8ac203bdf68ff9575f9c
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Todo
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -2,73 +2,83 @@
|
|
2
2
|
|
3
3
|
## Our Pledge
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
11
8
|
|
12
9
|
## Our Standards
|
13
10
|
|
14
|
-
Examples of behavior that contributes to
|
15
|
-
include:
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
16
12
|
|
17
|
-
*
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
22
18
|
|
23
|
-
Examples of unacceptable behavior
|
19
|
+
Examples of unacceptable behavior include:
|
24
20
|
|
25
|
-
* The use of sexualized language or imagery and
|
26
|
-
advances
|
27
|
-
* Trolling, insulting
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
28
24
|
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or
|
30
|
-
address, without explicit permission
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
31
27
|
* Other conduct which could reasonably be considered inappropriate in a
|
32
28
|
professional setting
|
33
29
|
|
34
|
-
##
|
30
|
+
## Enforcement Responsibilities
|
35
31
|
|
36
|
-
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
39
33
|
|
40
|
-
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
45
35
|
|
46
36
|
## Scope
|
47
37
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
54
39
|
|
55
40
|
## Enforcement
|
56
41
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@cpb.ca. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
67
73
|
|
68
74
|
## Attribution
|
69
75
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
|
71
|
-
available at
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
72
82
|
|
73
|
-
|
74
|
-
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/README.md
CHANGED
@@ -1,43 +1,130 @@
|
|
1
|
-
# Grokdown
|
1
|
+
# Grokdown: Markdown to Ruby Objects
|
2
2
|
|
3
|
-
|
3
|
+
`Grokdown` provides **an experimental interface** for building value objects and composing them into entities from a Markdown document tree.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
6
|
|
7
|
-
|
8
|
-
> - to empathize or communicate sympathetically (with); also, to experience
|
9
|
-
> enjoyment
|
7
|
+
Include the `Grokdown` module into ruby classes you want `Grokdown::Document` to consider building value objects from.
|
10
8
|
|
11
|
-
|
9
|
+
`Grokdown::Document` depends on class methods `matches_node?` and `agruments_from_node` to select which `Grokdown` class to build and how to build an instance from a Markdown node.
|
12
10
|
|
13
|
-
|
14
|
-
> format, then convert it to structurally valid XHTML (or HTML).
|
11
|
+
`Grokdown` instances can compose `Grokdown` value objects or entities by implementing instance hook methods following a naming convention. The hook method name is `add_` prefixing the snake case `Grokdown` class name of the instances a `Grokdown` instance can get added.
|
15
12
|
|
16
|
-
|
13
|
+
Implementing the hook methods creates precise and resilient factories for objects from Markdown documents.
|
14
|
+
|
15
|
+
Receiver | Hook method | Use case
|
16
|
+
--- | --- | ---
|
17
|
+
Class | `matches_node?` | Predicate to select receiving class to build from a given Markdown node|
|
18
|
+
Class | `arguments_from_node` | Maps node values to build an instance of the class from a given Markdown node |
|
19
|
+
Instance | `add_other_class_name` | Aggregate later `OtherClassName` instances when visiting the Markdown node tree |
|
20
|
+
|
21
|
+
Simple differences in implementations of `add_` composition methods enables building useful ruby object graphs from easy to write Markdown files.
|
22
|
+
|
23
|
+
### Extracting License information from README.md
|
24
|
+
|
25
|
+
Create a `.grokdown` file which defines types to build from markdown nodes, then use the `grokdown` CLI to extract the license name with:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
grokdown -e "Document.new(File.read('README.md')).first.license.name"
|
29
|
+
```
|
30
|
+
|
31
|
+
##### `README.md`
|
32
|
+
|
33
|
+
```
|
34
|
+
# Example Readme
|
17
35
|
|
18
|
-
|
36
|
+
Simple readme with a conventional `## License` section
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
```
|
42
|
+
|
43
|
+
##### `.grokdown`
|
19
44
|
|
20
45
|
```ruby
|
21
|
-
|
46
|
+
require "grokdown"
|
47
|
+
|
48
|
+
class Text < String
|
49
|
+
include Grokdown
|
50
|
+
|
51
|
+
def self.matches_node?(node) = node.type == :text
|
52
|
+
|
53
|
+
def self.arguments_from_node(node) = node.string_content
|
54
|
+
end
|
55
|
+
|
56
|
+
Link = Struct.new(:href, :title, :text, :parent, keyword_init: true) do
|
57
|
+
include Grokdown
|
58
|
+
|
59
|
+
def self.matches_node?(node) = node.type == :link
|
60
|
+
|
61
|
+
def self.arguments_from_node(node) = {href: node.url, title: node.title}
|
62
|
+
|
63
|
+
def add_text(node)
|
64
|
+
return if text
|
65
|
+
|
66
|
+
self.text = node
|
67
|
+
|
68
|
+
parent.add_composable(node) if parent&.can_compose?(node)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
License = Struct.new(:text, :href, :name, :link, keyword_init: true) do
|
73
|
+
include Grokdown
|
74
|
+
|
75
|
+
def self.matches_node?(node) = node.type == :header && node.header_level == 2 && node.first_child.string_content == "License"
|
76
|
+
|
77
|
+
def add_text(node) = self.text = node
|
78
|
+
|
79
|
+
extend Forwardable
|
80
|
+
|
81
|
+
def_delegator :link, :href
|
82
|
+
|
83
|
+
def add_link(node)
|
84
|
+
node.parent = self
|
85
|
+
self.link = node
|
86
|
+
end
|
87
|
+
|
88
|
+
def add_text(node) = self.name = node
|
89
|
+
end
|
90
|
+
|
91
|
+
Struct.new(:text, :link, :keyword_init) do
|
92
|
+
include Grokdown
|
93
|
+
|
94
|
+
def self.matches_node?(node) = node.type == :header && node.header_level == 2
|
95
|
+
|
96
|
+
def add_text(node) = self.text = node
|
97
|
+
def add_link(node) = self.link = node
|
98
|
+
end
|
99
|
+
|
100
|
+
Readme = Struct.new(:license) do
|
101
|
+
include Grokdown
|
102
|
+
|
103
|
+
def self.matches_node?(node) = node.type == :document
|
104
|
+
|
105
|
+
def add_license(node) = self.license = node
|
106
|
+
end
|
22
107
|
```
|
23
108
|
|
24
|
-
|
109
|
+
## Installation
|
110
|
+
|
111
|
+
Install the gem and add to the application's Gemfile by executing:
|
25
112
|
|
26
|
-
$ bundle
|
113
|
+
$ bundle add grokdown
|
27
114
|
|
28
|
-
|
115
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
29
116
|
|
30
117
|
$ gem install grokdown
|
31
118
|
|
32
119
|
## Development
|
33
120
|
|
34
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
121
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
122
|
|
36
|
-
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
|
123
|
+
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).
|
37
124
|
|
38
125
|
## Contributing
|
39
126
|
|
40
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
127
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cpb/grokdown. 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/cpb/grokdown/blob/main/CODE_OF_CONDUCT.md).
|
41
128
|
|
42
129
|
## License
|
43
130
|
|
@@ -45,4 +132,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
45
132
|
|
46
133
|
## Code of Conduct
|
47
134
|
|
48
|
-
Everyone interacting in the Grokdown project
|
135
|
+
Everyone interacting in the Grokdown project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cpb/grokdown/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
3
7
|
|
4
|
-
|
5
|
-
t.libs << "test"
|
6
|
-
t.libs << "lib"
|
7
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
-
end
|
8
|
+
require "standard/rake"
|
9
9
|
|
10
|
-
task :
|
10
|
+
task default: %i[spec standard]
|
data/exe/grokdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
|
8
|
+
require "grokdown"
|
9
|
+
require "grokdown/document"
|
10
|
+
|
11
|
+
document_definition = Pathname.glob(".grokdown").find { _1.exist? }
|
12
|
+
|
13
|
+
load document_definition
|
14
|
+
|
15
|
+
parser = OptionParser.new
|
16
|
+
|
17
|
+
parser.on("-e [ruby expression]", "Ruby expression to evaluate after loading the Grokdown document definition") do |value|
|
18
|
+
puts Grokdown.module_eval(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
parser.parse!
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Grokdown
|
2
|
+
module Composing
|
3
|
+
def self.extended(base) = base.include(InstanceMethods)
|
4
|
+
|
5
|
+
def can_compose?(object) = public_instance_methods.include?(composition_method(object))
|
6
|
+
|
7
|
+
def composition_method(object)
|
8
|
+
:"add_#{object.class.name.gsub(/#<.*>::/,"").gsub("::", "_").gsub(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }.downcase}" if object.class.name
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def can_compose?(object) = self.class.can_compose?(object)
|
13
|
+
|
14
|
+
def composition_method(object) = self.class.composition_method(object)
|
15
|
+
|
16
|
+
def add_composable(object)
|
17
|
+
public_send(composition_method(object), object)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/grokdown/creating.rb
CHANGED
@@ -1,57 +1,44 @@
|
|
1
|
-
require
|
1
|
+
require "grokdown"
|
2
2
|
|
3
3
|
module Grokdown
|
4
4
|
module Creating
|
5
|
-
|
6
5
|
def self.extended(base)
|
7
|
-
base.send(:include,InstanceMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
mod = self
|
11
|
-
define_method(:recurse) { mod }
|
12
|
-
|
13
|
-
def create(many: false, &block)
|
14
|
-
@create = block
|
15
|
-
@create_many = many
|
6
|
+
base.send(:include, InstanceMethods)
|
16
7
|
end
|
17
8
|
|
18
9
|
def build(node)
|
19
|
-
|
20
|
-
args =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
10
|
+
begin
|
11
|
+
return collection_of_arguments_from_node(node).map { |args| _build(args, false) { |i| i.node = node } } if respond_to?(:collection_of_arguments_from_node)
|
12
|
+
rescue NoMethodError => e
|
13
|
+
raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} collection_of_arguments_from_node"
|
14
|
+
rescue CommonMarker::NodeError
|
15
|
+
raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} collection_of_arguments_from_node"
|
16
|
+
end
|
27
17
|
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
begin
|
19
|
+
return _build(arguments_from_node(node)) { |i| i.node = node } if respond_to?(:arguments_from_node)
|
20
|
+
rescue NoMethodError => e
|
21
|
+
raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} arguments_from_node"
|
22
|
+
rescue CommonMarker::NodeError
|
23
|
+
raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} arguments_from_node"
|
31
24
|
end
|
25
|
+
|
26
|
+
new.tap { |i| i.node = node }
|
32
27
|
end
|
33
28
|
|
34
|
-
private def _build(args,recurse=true
|
29
|
+
private def _build(args, recurse = true, &block)
|
35
30
|
case args
|
36
31
|
when Hash
|
37
32
|
if self < Hash
|
38
33
|
new.merge!(args).tap(&block)
|
39
|
-
|
40
34
|
else
|
41
35
|
new(**args).tap(&block)
|
42
|
-
|
43
36
|
end
|
44
37
|
when Array
|
45
|
-
if
|
46
|
-
args.
|
38
|
+
if self < Array
|
39
|
+
new(args).tap(&block)
|
47
40
|
else
|
48
|
-
|
49
|
-
new(args).tap(&block)
|
50
|
-
|
51
|
-
else
|
52
|
-
new(*args).tap(&block)
|
53
|
-
|
54
|
-
end
|
41
|
+
new(*args).tap(&block)
|
55
42
|
end
|
56
43
|
else
|
57
44
|
new(*args).tap(&block)
|
data/lib/grokdown/document.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "commonmarker"
|
2
|
+
require "grokdown"
|
3
|
+
require "grokdown/matching"
|
4
|
+
require "grokdown/never_composes"
|
5
5
|
|
6
6
|
module Grokdown
|
7
7
|
class Document
|
@@ -9,12 +9,12 @@ module Grokdown
|
|
9
9
|
@walk = []
|
10
10
|
@nodes = []
|
11
11
|
|
12
|
-
CommonMarker.render_doc(markdown,options,extensions).reduce(self) do |doc, node|
|
12
|
+
CommonMarker.render_doc(markdown, options, extensions).walk.reduce(self) do |doc, node|
|
13
13
|
decorated_node = case node
|
14
14
|
when Matching
|
15
15
|
Matching.for(node).build(node)
|
16
16
|
else
|
17
|
-
|
17
|
+
NeverComposes.new(node)
|
18
18
|
end
|
19
19
|
|
20
20
|
doc.push decorated_node
|
@@ -22,7 +22,8 @@ module Grokdown
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def push(node)
|
25
|
-
case node
|
25
|
+
case node
|
26
|
+
when Matching
|
26
27
|
_push(node)
|
27
28
|
when Array
|
28
29
|
node.each do |n|
|
@@ -36,8 +37,8 @@ module Grokdown
|
|
36
37
|
end
|
37
38
|
|
38
39
|
private def _push(node)
|
39
|
-
if accepts = @walk.reverse.find {|i| i.
|
40
|
-
accepts.
|
40
|
+
if (accepts = @walk.reverse.find { |i| i.can_compose?(node) })
|
41
|
+
accepts.add_composable(node)
|
41
42
|
else
|
42
43
|
@nodes.push(node)
|
43
44
|
end
|
data/lib/grokdown/matching.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "commonmarker/node"
|
2
|
+
require "grokdown"
|
3
3
|
|
4
4
|
module Grokdown
|
5
5
|
module Matching
|
@@ -11,22 +11,20 @@ module Grokdown
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def matches?(node)
|
14
|
-
@@knowns.any? {|i| i.matches?(node)}
|
14
|
+
@@knowns.any? { |i| i.matches?(node) }
|
15
15
|
end
|
16
16
|
|
17
17
|
def for(node)
|
18
|
-
@@knowns.find {|i| i.matches?(node)}
|
18
|
+
@@knowns.find { |i| i.matches?(node) }
|
19
19
|
end
|
20
20
|
|
21
21
|
alias_method :===, :matches?
|
22
22
|
end
|
23
23
|
|
24
|
-
def match(&block)
|
25
|
-
@matcher = block
|
26
|
-
end
|
27
|
-
|
28
24
|
def matches?(node)
|
29
|
-
node.is_a?(self) || (node.is_a?(CommonMarker::Node) &&
|
25
|
+
node.is_a?(self) || (node.is_a?(CommonMarker::Node) && matches_node?(node))
|
26
|
+
rescue NoMethodError => e
|
27
|
+
raise NotImplementedError, "expected #{self} to implement #matches_node?(node) but got: #{e.message}"
|
30
28
|
end
|
31
29
|
|
32
30
|
alias_method :===, :matches?
|
data/lib/grokdown/version.rb
CHANGED
data/lib/grokdown.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "grokdown/composing"
|
4
|
+
require_relative "grokdown/creating"
|
5
|
+
require_relative "grokdown/matching"
|
6
|
+
require_relative "grokdown/version"
|
2
7
|
|
3
8
|
module Grokdown
|
4
9
|
class Error < StandardError; end
|
5
|
-
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend(Matching)
|
13
|
+
base.extend(Creating)
|
14
|
+
base.extend(Composing)
|
15
|
+
end
|
6
16
|
end
|
data/sig/grokdown.rbs
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grokdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Buxton
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commonmarker
|
@@ -16,98 +16,47 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.17'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.17'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '5.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.12.2
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.12.2
|
26
|
+
version: '0'
|
83
27
|
description: Grok Markdown documents with Ruby objects.
|
84
28
|
email:
|
85
29
|
- me@cpb.ca
|
86
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- grokdown
|
87
32
|
extensions: []
|
88
33
|
extra_rdoc_files: []
|
89
34
|
files:
|
90
|
-
- ".
|
35
|
+
- ".rspec"
|
36
|
+
- ".ruby-version"
|
37
|
+
- ".standard.yml"
|
38
|
+
- CHANGELOG.md
|
91
39
|
- CODE_OF_CONDUCT.md
|
92
|
-
- Gemfile
|
93
40
|
- LICENSE.txt
|
94
41
|
- README.md
|
95
42
|
- Rakefile
|
96
|
-
-
|
97
|
-
- bin/setup
|
98
|
-
- grokdown.gemspec
|
43
|
+
- exe/grokdown
|
99
44
|
- lib/grokdown.rb
|
100
|
-
- lib/grokdown/
|
45
|
+
- lib/grokdown/composing.rb
|
101
46
|
- lib/grokdown/creating.rb
|
102
47
|
- lib/grokdown/document.rb
|
103
48
|
- lib/grokdown/matching.rb
|
104
|
-
- lib/grokdown/
|
49
|
+
- lib/grokdown/never_composes.rb
|
105
50
|
- lib/grokdown/version.rb
|
106
|
-
|
51
|
+
- sig/grokdown.rbs
|
52
|
+
homepage: https://github.com/cpb/grokdown
|
107
53
|
licenses:
|
108
54
|
- MIT
|
109
|
-
metadata:
|
110
|
-
|
55
|
+
metadata:
|
56
|
+
homepage_uri: https://github.com/cpb/grokdown
|
57
|
+
source_code_uri: https://github.com/cpb/grokdown
|
58
|
+
changelog_uri: https://github.com/cpb/grokdown/blob/main/CHANGELOG.md
|
59
|
+
post_install_message:
|
111
60
|
rdoc_options: []
|
112
61
|
require_paths:
|
113
62
|
- lib
|
@@ -122,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
71
|
- !ruby/object:Gem::Version
|
123
72
|
version: '0'
|
124
73
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
126
|
-
signing_key:
|
74
|
+
rubygems_version: 3.5.14
|
75
|
+
signing_key:
|
127
76
|
specification_version: 4
|
128
77
|
summary: Grok Markdown documents with Ruby objects.
|
129
78
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "grokdown"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/grokdown.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "grokdown/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "grokdown"
|
8
|
-
spec.version = Grokdown::VERSION
|
9
|
-
spec.authors = ["Caleb Buxton"]
|
10
|
-
spec.email = ["me@cpb.ca"]
|
11
|
-
|
12
|
-
spec.summary = \
|
13
|
-
spec.description = %q{Grok Markdown documents with Ruby objects.}
|
14
|
-
spec.homepage = "https://github.com/trykinside/grokdown"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Specify which files should be added to the gem when it is released.
|
18
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
-
end
|
22
|
-
spec.bindir = "exe"
|
23
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = ["lib"]
|
25
|
-
|
26
|
-
spec.add_dependency "commonmarker", "~> 0.20.1"
|
27
|
-
spec.add_development_dependency "bundler", "~> 1.17"
|
28
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
-
spec.add_development_dependency "pry", "~> 0.12.2"
|
31
|
-
end
|
data/lib/grokdown/consuming.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'grokdown'
|
2
|
-
|
3
|
-
module Grokdown
|
4
|
-
module Consuming
|
5
|
-
def self.extended(base)
|
6
|
-
base.send(:include,InstanceMethods)
|
7
|
-
end
|
8
|
-
|
9
|
-
def consumes?(node)
|
10
|
-
@consumables ||= {}
|
11
|
-
@consumables.has_key?(node.class)
|
12
|
-
end
|
13
|
-
|
14
|
-
def consumes(mapping={})
|
15
|
-
@consumables = mapping
|
16
|
-
end
|
17
|
-
|
18
|
-
def consume(inst,node)
|
19
|
-
@consumables ||= {}
|
20
|
-
inst.send(@consumables.fetch(node.class),node)
|
21
|
-
rescue KeyError
|
22
|
-
raise ArgumentError, "#{inst.class} cannot consume #{node.class}"
|
23
|
-
end
|
24
|
-
|
25
|
-
module InstanceMethods
|
26
|
-
def consumes?(node)
|
27
|
-
self.class.consumes?(node)
|
28
|
-
end
|
29
|
-
|
30
|
-
def consume(node)
|
31
|
-
self.class.consume(self,node)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Grokdown
|
2
|
-
class NeverConsumes < BasicObject
|
3
|
-
def initialize(node)
|
4
|
-
@node = node
|
5
|
-
end
|
6
|
-
|
7
|
-
def consumes?(*)
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
def method_missing(name,*args,**kargs,&block)
|
12
|
-
if kargs.empty?
|
13
|
-
@node.send(name,*args,&block)
|
14
|
-
else
|
15
|
-
@node.send(name,*args,**kargs,&block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def node
|
20
|
-
@node
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|