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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f731dbda7891bc9e34a6db41213f3f6bbb0837e6a0e4e807679d96339643fb1
4
- data.tar.gz: e281170c1b32d41496268adf46a1308f04d7b510b66d98a29ecf48b472b8ec24
3
+ metadata.gz: ac8a98fe8b785069748b8188029679769d84f1a4b7b8cf92abe5168669e0f5dd
4
+ data.tar.gz: e447bf05e89b2726b9715984d1e74fbb756c00400173efda99da59cedcc53bb8
5
5
  SHA512:
6
- metadata.gz: 698f3d961189f7662253c42ff31080e83bbffc7b34508c5e7332c927664143cea100300cae2927aaf9be7a8baf3cd12fd99dd3f86b02fc1e709a5af39284013b
7
- data.tar.gz: f583610c855d74aa2f2a9a34c0b31bc86bb39d653cdf21aedb3f85aa393c4bd75b0f0fc4eae2bf736470f2cd258bf9595c7c8fc2a2d75cc98bd0de312278f1a2
6
+ metadata.gz: ddbc26e585b14064b760417a7b3108f385f7df479497fa2753ed22b24a613f8f9175427b540a41c217b85a5b0288782465de95076cc7d6b6ad42cd3f98818dd3
7
+ data.tar.gz: 18ffe9aa81977fe8c99c016ad95cd6bb77502ac85cc88c3f22848db0c945e43331af8b91dae20ee55fe6c4faa3e5fcdebb83474bf8ca8ac203bdf68ff9575f9c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
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
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
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 creating a positive environment
15
- include:
11
+ Examples of behavior that contributes to a positive environment for our community include:
16
12
 
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
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 by participants include:
19
+ Examples of unacceptable behavior include:
24
20
 
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
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 electronic
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
- ## Our Responsibilities
30
+ ## Enforcement Responsibilities
35
31
 
36
- Project maintainers are responsible for clarifying the standards of acceptable
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
- Project maintainers have the right and responsibility to remove, edit, or
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 both within project spaces and in public spaces
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
- reported by contacting the project team at caleb@kinside.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
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
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
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 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
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
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
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
- Grok Markdown documents with Ruby objects. Have fun using whats inside Markdown documents, without all of the pain of walking a document tree.
3
+ `Grokdown` provides **an experimental interface** for building value objects and composing them into entities from a Markdown document tree.
4
4
 
5
- ## Grok
5
+ ## Usage
6
6
 
7
- > - to understand intuitively or by empathy, to establish rapport with
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
- ## Markdown
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
- > Markdown allows you to write using an easy-to-read, easy-to-write plain text
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
- ## Installation
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
- Add this line to your application's Gemfile:
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
- gem 'grokdown'
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
- And then execute:
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
- Or install it yourself as:
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 test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/trykinside/grokdown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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 projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cpb/grokdown/blob/master/CODE_OF_CONDUCT.md).
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 "rake/testtask"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
3
7
 
4
- Rake::TestTask.new(:test) do |t|
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 :default => :test
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
@@ -1,57 +1,44 @@
1
- require 'grokdown'
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
- if @create
20
- args = begin
21
- @create.call(node)
22
- rescue NoMethodError => e
23
- raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
24
- rescue CommonMarker::NodeError => e
25
- raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
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
- _build(args) {|i| i.node=node }
29
- else
30
- new.tap do |i| i.node=node end
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,&block)
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 @create_many && recurse
46
- args.map {|i| _build(i,false,&block) }
38
+ if self < Array
39
+ new(args).tap(&block)
47
40
  else
48
- if self < Array
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)
@@ -1,7 +1,7 @@
1
- require 'commonmarker'
2
- require 'grokdown'
3
- require 'grokdown/matching'
4
- require 'grokdown/never_consumes'
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
- NeverConsumes.new(node)
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 when Matching
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.consumes?(node) }
40
- accepts.consume(node)
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
@@ -1,5 +1,5 @@
1
- require 'commonmarker/node'
2
- require 'grokdown'
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) && @matcher.call(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?
@@ -0,0 +1,13 @@
1
+ require "delegate"
2
+
3
+ module Grokdown
4
+ class NeverComposes < SimpleDelegator
5
+ def can_compose?(*) = false
6
+
7
+ def ==(other)
8
+ to_commonmark == other.to_commonmark
9
+ end
10
+
11
+ alias_method :node, :__getobj__
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grokdown
2
- VERSION = "0.2.1"
4
+ VERSION = "0.4.0"
3
5
  end
data/lib/grokdown.rb CHANGED
@@ -1,6 +1,16 @@
1
- require "grokdown/version"
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
- # Your code goes here...
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
@@ -0,0 +1,4 @@
1
+ module Grokdown
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
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.2.1
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: 2020-01-03 00:00:00.000000000 Z
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.20.1
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.20.1
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
- - ".gitignore"
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
- - bin/console
97
- - bin/setup
98
- - grokdown.gemspec
43
+ - exe/grokdown
99
44
  - lib/grokdown.rb
100
- - lib/grokdown/consuming.rb
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/never_consumes.rb
49
+ - lib/grokdown/never_composes.rb
105
50
  - lib/grokdown/version.rb
106
- homepage: https://github.com/trykinside/grokdown
51
+ - sig/grokdown.rbs
52
+ homepage: https://github.com/cpb/grokdown
107
53
  licenses:
108
54
  - MIT
109
- metadata: {}
110
- post_install_message:
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.0.4
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
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in grokdown.gemspec
6
- gemspec
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
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
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
@@ -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