grokdown 0.2.0 → 0.3.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: 0df4042c8ccc179f5294c0b1e19e12b231d6bb152795d0fcf44a0aa68e8bb8ed
4
- data.tar.gz: beb8f749febaf3f8de2097f5f4206328ba4083bfd872257ce67b58742228a2ef
3
+ metadata.gz: 6d40e626d89381d669dd420c80541f010aa0081f788fd5728feb40e5c2573a1a
4
+ data.tar.gz: 312883afadca7036f18f42ef6f417b6d1f7117f7dabf174122200e392624ad7c
5
5
  SHA512:
6
- metadata.gz: 4b4ac09e38dd8b5cfee67ddf23bc1b0b90893a35473a7be7d519b1d02286d643494890543233c6dc194c156294490e1db497a3efc4b31e834fec0de0f835870a
7
- data.tar.gz: 78b56dce2afa9c0711fb4f56ac8e8ef31ec90b9be52488567b0af532f2f8814419c5fa23806dad6b98f91f0c6f2634cec9ada24a5d83e162ace1aa360d7d6f9f
6
+ metadata.gz: eae64369ef2ad249bbc2d03e130e21da7977bd4157b5a813fb9032238fa2afae8b76f316add2aa330dd725f10a06bb9ae22be16d72f961a7c8677d36479bd90b
7
+ data.tar.gz: 69e31f53ed7131294cd9f16940f7a6d1f74ae689f8177c6ad552e1751c58eecdce5799282ca2e88cf11c0bd44d3910c6296bf5d118513274166640732e7dd75a
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
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
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.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
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
18
+
19
+ Examples of unacceptable behavior include:
20
+
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
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
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.
33
+
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.
35
+
36
+ ## Scope
37
+
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.
39
+
40
+ ## Enforcement
41
+
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.
59
+
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.
73
+
74
+ ## Attribution
75
+
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
82
+
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Caleb Buxton
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
@@ -13,12 +13,28 @@ Grok Markdown documents with Ruby objects. Have fun using whats inside Markdown
13
13
  > Markdown allows you to write using an easy-to-read, easy-to-write plain text
14
14
  > format, then convert it to structurally valid XHTML (or HTML).
15
15
 
16
+ ## Installation
17
+
18
+ Install the gem and add to the application's Gemfile by executing:
19
+ $ bundle add grokdown
20
+
21
+ If bundler is not being used to manage dependencies, install the gem by executing:
22
+ $ gem install grokdown
23
+
16
24
  ## Development
17
25
 
18
- 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.
26
+ 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.
19
27
 
20
- 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).
28
+ 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).
21
29
 
22
30
  ## Contributing
23
31
 
24
- Bug reports and pull requests are welcome on GitHub at https://github.com/cpb/grokdown.
32
+ 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).
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ ## Code of Conduct
39
+
40
+ 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 ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -1,9 +1,9 @@
1
- require 'grokdown'
1
+ require "grokdown"
2
2
 
3
3
  module Grokdown
4
4
  module Consuming
5
5
  def self.extended(base)
6
- base.send(:include,InstanceMethods)
6
+ base.send(:include, InstanceMethods)
7
7
  end
8
8
 
9
9
  def consumes?(node)
@@ -11,13 +11,13 @@ module Grokdown
11
11
  @consumables.has_key?(node.class)
12
12
  end
13
13
 
14
- def consumes(mapping={})
14
+ def consumes(mapping = {})
15
15
  @consumables = mapping
16
16
  end
17
17
 
18
- def consume(inst,node)
18
+ def consume(inst, node)
19
19
  @consumables ||= {}
20
- inst.send(@consumables.fetch(node.class),node)
20
+ inst.send(@consumables.fetch(node.class), node)
21
21
  rescue KeyError
22
22
  raise ArgumentError, "#{inst.class} cannot consume #{node.class}"
23
23
  end
@@ -28,7 +28,7 @@ module Grokdown
28
28
  end
29
29
 
30
30
  def consume(node)
31
- self.class.consume(self,node)
31
+ self.class.consume(self, node)
32
32
  end
33
33
  end
34
34
  end
@@ -1,15 +1,11 @@
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)
6
+ base.send(:include, InstanceMethods)
8
7
  end
9
8
 
10
- mod = self
11
- define_method(:recurse) { mod }
12
-
13
9
  def create(many: false, &block)
14
10
  @create = block
15
11
  @create_many = many
@@ -20,16 +16,18 @@ module Grokdown
20
16
  args = begin
21
17
  @create.call(node)
22
18
  rescue NoMethodError => e
23
- raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]}"
19
+ raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
20
+ rescue CommonMarker::NodeError
21
+ raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
24
22
  end
25
23
 
26
- _build(args) {|i| i.node=node }
24
+ _build(args) { |i| i.node = node }
27
25
  else
28
- new.tap do |i| i.node=node end
26
+ new.tap { |i| i.node = node }
29
27
  end
30
28
  end
31
29
 
32
- private def _build(args,recurse=true,&block)
30
+ private def _build(args, recurse = true, &block)
33
31
  case args
34
32
  when Hash
35
33
  if self < Hash
@@ -41,15 +39,13 @@ module Grokdown
41
39
  end
42
40
  when Array
43
41
  if @create_many && recurse
44
- args.map {|i| _build(i,false,&block) }
45
- else
46
- if self < Array
47
- new(args).tap(&block)
42
+ args.map { |i| _build(i, false, &block) }
43
+ elsif self < Array
44
+ new(args).tap(&block)
48
45
 
49
- else
50
- new(*args).tap(&block)
46
+ else
47
+ new(*args).tap(&block)
51
48
 
52
- end
53
49
  end
54
50
  else
55
51
  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_consumes"
5
5
 
6
6
  module Grokdown
7
7
  class Document
@@ -9,7 +9,7 @@ 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)
@@ -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,7 +37,7 @@ module Grokdown
36
37
  end
37
38
 
38
39
  private def _push(node)
39
- if accepts = @walk.reverse.find {|i| i.consumes?(node) }
40
+ if (accepts = @walk.reverse.find { |i| i.consumes?(node) })
40
41
  accepts.consume(node)
41
42
  else
42
43
  @nodes.push(node)
@@ -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,11 +11,11 @@ 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?
@@ -1,23 +1,13 @@
1
- module Grokdown
2
- class NeverConsumes < BasicObject
3
- def initialize(node)
4
- @node = node
5
- end
1
+ require "delegate"
6
2
 
7
- def consumes?(*)
8
- false
9
- end
3
+ module Grokdown
4
+ class NeverConsumes < SimpleDelegator
5
+ def consumes?(*) = false
10
6
 
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
7
+ def ==(other)
8
+ to_commonmark == other.to_commonmark
17
9
  end
18
10
 
19
- def node
20
- @node
21
- end
11
+ alias_method :node, :__getobj__
22
12
  end
23
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grokdown
2
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
3
5
  end
data/lib/grokdown.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "grokdown/version"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "grokdown/version"
2
4
 
3
5
  module Grokdown
4
6
  class Error < StandardError; 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.0
4
+ version: 0.3.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: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2024-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commonmarker
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
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
83
27
  description: Grok Markdown documents with Ruby objects.
84
28
  email:
85
29
  - me@cpb.ca
@@ -87,9 +31,13 @@ executables: []
87
31
  extensions: []
88
32
  extra_rdoc_files: []
89
33
  files:
90
- - ".gitignore"
34
+ - ".rspec"
35
+ - ".ruby-version"
36
+ - ".standard.yml"
37
+ - CODE_OF_CONDUCT.md
38
+ - LICENSE.txt
91
39
  - README.md
92
- - grokdown.gemspec
40
+ - Rakefile
93
41
  - lib/grokdown.rb
94
42
  - lib/grokdown/consuming.rb
95
43
  - lib/grokdown/creating.rb
@@ -97,10 +45,15 @@ files:
97
45
  - lib/grokdown/matching.rb
98
46
  - lib/grokdown/never_consumes.rb
99
47
  - lib/grokdown/version.rb
48
+ - sig/grokdown.rbs
100
49
  homepage: https://github.com/cpb/grokdown
101
- licenses: []
102
- metadata: {}
103
- post_install_message:
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/cpb/grokdown
54
+ source_code_uri: https://github.com/cpb/grokdown
55
+ changelog_uri: https://github.com/cpb/grokdown/blob/main/CODE_OF_CONDUCT.md
56
+ post_install_message:
104
57
  rdoc_options: []
105
58
  require_paths:
106
59
  - lib
@@ -115,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
68
  - !ruby/object:Gem::Version
116
69
  version: '0'
117
70
  requirements: []
118
- rubygems_version: 3.0.4
119
- signing_key:
71
+ rubygems_version: 3.5.9
72
+ signing_key:
120
73
  specification_version: 4
121
74
  summary: Grok Markdown documents with Ruby objects.
122
75
  test_files: []
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/grokdown.gemspec DELETED
@@ -1,30 +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/cpb/grokdown"
15
-
16
- # Specify which files should be added to the gem when it is released.
17
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
- end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
24
-
25
- spec.add_dependency "commonmarker", "~> 0.20.1"
26
- spec.add_development_dependency "bundler", "~> 1.17"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "minitest", "~> 5.0"
29
- spec.add_development_dependency "pry", "~> 0.12.2"
30
- end