gemtext 1.0.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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1392d564c448b924956632750348b03f7804d62ab1e3b925c212b25d44f613bb
4
+ data.tar.gz: 16d8245dda4b5356bf5adbd0d2070dbd6b28239c096de688c47126990656a0cc
5
+ SHA512:
6
+ metadata.gz: 98a51c3e848abcd5cc1d1d7840d56ed0e7cc916ce2546db688e06faf4b4920b35568f2d23c13404add1e2751cc9440fe1e266ddc2dd996fd71344a154b2925fd
7
+ data.tar.gz: a39c9d52790e8cbf6481edd59d893a73e210742e8513eb7a823b511d81dbb2dd32b6caf26e1a465dca784fae353bd640e2437e53b5b3a75a485d5d30aaf07eb9
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## v1.0.0
4
+
5
+ * Parse a Gemtext::Document from a Ruby IO
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
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.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
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
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
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
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
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.
39
+
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.
45
+
46
+ ## Scope
47
+
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.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at git@exastencil.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.
63
+
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.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gemtext.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Exa Stencil
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.
@@ -0,0 +1,48 @@
1
+ # Gemtext
2
+
3
+ This gem provides data structures and parsing capabilities for
4
+ [gemtext](https://gemini.circumlunar.space/docs/specification.html)
5
+ (text/gemini). Gemtext is pretty simple, so this is just meant to save
6
+ you some work.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'gemtext'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install gemtext
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ Gemtext.parse(io)
28
+ #=> <#Gemtext::Document>
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/exastencil/gemtext. 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/exastencil/gemtext/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the Gemtext project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/exastencil/gemtext/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
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
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gemtext"
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__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/gemtext/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "gemtext"
5
+ spec.version = Gemtext::VERSION
6
+ spec.authors = ["Exa Stencil"]
7
+ spec.email = ["git@exastencil.com"]
8
+
9
+ spec.summary = %q{Gemtext parser for Ruby}
10
+ spec.description = %q{Produces a Gemtext::Document of Gemtext::Nodes from a Ruby IO}
11
+ spec.homepage = "https://github.com/exastencil/gemtext"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/exastencil/gemtext"
17
+ spec.metadata["changelog_uri"] = "https://github.com/exastencil/gemtext/blob/main/CHANGELOG.md"
18
+
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
+ end
@@ -0,0 +1,6 @@
1
+ require 'gemtext/version'
2
+ require 'gemtext/parser'
3
+
4
+ module Gemtext
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,27 @@
1
+ require 'gemtext/node'
2
+ require 'gemtext/heading'
3
+ require 'gemtext/sub_heading'
4
+ require 'gemtext/sub_sub_heading'
5
+ require 'gemtext/whitespace'
6
+ require 'gemtext/text'
7
+ require 'gemtext/list_item'
8
+ require 'gemtext/link'
9
+ require 'gemtext/preformatted'
10
+ require 'gemtext/quote'
11
+
12
+ module Gemtext
13
+ # `Gemtext::Document` represents a gemtext document or "page". It
14
+ # consists of a sequence of `Gemtext::Node`s
15
+ class Document
16
+ # Nodes
17
+ attr_reader :nodes
18
+
19
+ def initialize
20
+ @nodes = []
21
+ end
22
+
23
+ def push(node)
24
+ @nodes << node if node.is_a? Gemtext::Node
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Gemtext
2
+ class Heading < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Gemtext
2
+ class Link < Node
3
+ attr_reader :description
4
+ attr_reader :target
5
+
6
+ def initialize(content)
7
+ super content
8
+ @target = @content.split(/\s+/).first
9
+ @description = content.delete_prefix(@target).strip
10
+ end
11
+
12
+ def self.[](target, description = nil)
13
+ new "#{target} #{description}"
14
+ end
15
+
16
+ def ==(other)
17
+ other.class == self.class && other.target == @target && other.description == @description
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Gemtext
2
+ class ListItem < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Gemtext
2
+ # `Gemtext::Node` represents a piece of a document. There are
3
+ # a limited number of node types. They store their content with any
4
+ # formatting needed to identify that content removed.
5
+ class Node
6
+ # The content of the node
7
+ attr_reader :content
8
+
9
+ def initialize(content = nil)
10
+ @content = content
11
+ end
12
+
13
+ def inspect
14
+ "#{self.class}{#{content}}"
15
+ end
16
+
17
+ def ==(other)
18
+ other.class == self.class && other.content == @content
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ require 'gemtext/document'
2
+
3
+ module Gemtext
4
+ class Parser
5
+ def initialize(io)
6
+ @io = io
7
+ @document = Document.new
8
+ @preformatted = false
9
+ end
10
+
11
+ def parse
12
+ @io.each do |line|
13
+ # Always strip lines to handle "\r\n"
14
+ stripped = line.strip
15
+
16
+ # First check if we're toggling preformatted mode
17
+ if stripped =~ /^```/
18
+ if @preformatted
19
+ # Closing out the preformatted text
20
+ @preformatted.content.delete_suffix!("\n") # Remove the extra newline from the last line
21
+ @document.push @preformatted
22
+ @preformatted = false
23
+ elsif stripped == '```'
24
+ # Starting preformatted text without caption
25
+ @preformatted = Preformatted[""]
26
+ else
27
+ # Starting preformatted text with caption
28
+ @preformatted = Preformatted["", stripped.delete_prefix('```').strip]
29
+ end
30
+ next
31
+ end
32
+
33
+ # Once we're in a preformatted block add to the block until we
34
+ # break out of it
35
+ if @preformatted
36
+ @preformatted.content << line
37
+ next
38
+ end
39
+
40
+ @document.push(
41
+ case stripped
42
+ when /^#\s+/
43
+ Heading[stripped.delete_prefix('#').strip]
44
+ when /^##\s+/
45
+ SubHeading[stripped.delete_prefix('##').strip]
46
+ when /^###\s+/
47
+ SubSubHeading[stripped.delete_prefix('###').strip]
48
+ when ""
49
+ Whitespace[nil]
50
+ when /^=>/
51
+ without_arrow = stripped.delete_prefix('=>').strip
52
+ pieces = without_arrow.split /\s+/
53
+ url = pieces.first
54
+ description = pieces.drop(1).join ' ' # TODO: Preserve whitespace in description
55
+
56
+ Link[url, description]
57
+ when /^\*\s/
58
+ ListItem[stripped.delete_prefix('*').strip]
59
+ when /^>/
60
+ Quote[stripped.delete_prefix('>').strip]
61
+ else
62
+ Text[line.strip]
63
+ end
64
+ )
65
+ end
66
+ @document.dup
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,16 @@
1
+ module Gemtext
2
+ class Preformatted < Node
3
+ def initialize(content, caption = nil)
4
+ super content
5
+ @caption = caption
6
+ end
7
+
8
+ def self.[](content, caption = nil)
9
+ new content, caption
10
+ end
11
+
12
+ def inspect
13
+ "#{self.class}{#{content}|{#{@caption}}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module Gemtext
2
+ class Quote < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Gemtext
2
+ class SubHeading < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+
7
+ def inspect
8
+ "#{self.class}{#{content}}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Gemtext
2
+ class SubSubHeading < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Gemtext
2
+ class Text < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+
7
+ def ==(other)
8
+ other.class == self.class && other.content == @content
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Gemtext
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ module Gemtext
2
+ class Whitespace < Node
3
+ def self.[](content)
4
+ new content
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemtext
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Exa Stencil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Produces a Gemtext::Document of Gemtext::Nodes from a Ruby IO
14
+ email:
15
+ - git@exastencil.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - gemtext.gemspec
31
+ - lib/gemtext.rb
32
+ - lib/gemtext/document.rb
33
+ - lib/gemtext/heading.rb
34
+ - lib/gemtext/link.rb
35
+ - lib/gemtext/list_item.rb
36
+ - lib/gemtext/node.rb
37
+ - lib/gemtext/parser.rb
38
+ - lib/gemtext/preformatted.rb
39
+ - lib/gemtext/quote.rb
40
+ - lib/gemtext/sub_heading.rb
41
+ - lib/gemtext/sub_sub_heading.rb
42
+ - lib/gemtext/text.rb
43
+ - lib/gemtext/version.rb
44
+ - lib/gemtext/whitespace.rb
45
+ homepage: https://github.com/exastencil/gemtext
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/exastencil/gemtext
50
+ source_code_uri: https://github.com/exastencil/gemtext
51
+ changelog_uri: https://github.com/exastencil/gemtext/blob/main/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.4
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Gemtext parser for Ruby
71
+ test_files: []