diml 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e688225588d8e5239464efa0873e93b07be46ac97dcfece27d93f9754a0210f
4
- data.tar.gz: 5f7fd51e1eac09ee9b35178733cf61ffd20a3c2419a08780ae8e312ce18dcbca
3
+ metadata.gz: 23c58059fc446032dddbbda976bab077dd3abad4767f344e010f73958eda0ec1
4
+ data.tar.gz: 64384b3c993c53cce0150197708152f9b28b6940181aee0e22d3f41cc0c369fb
5
5
  SHA512:
6
- metadata.gz: 2de69226a26a89556b7e31080fe661e17b969605fca5cea38f11a58157b471f6bba1c2e5900b1d7fd1533600ca656c61cfc600a356daf39d536ac093c1ced669
7
- data.tar.gz: 0432da9d0f971c2d4f8216a7520e202956ec88e9ec6df2fe6cab8f40e40e2a57511c486ab42e4b8dfe7926a7106346666e3cdb5bc8aebb208852e4537dc004d3
6
+ metadata.gz: 4ccaf1cf6a0c94aec38ebc72e70a622c96d545115edc6c9edd51a7231fa2fde09735f7a796a603f70c355646536a4fb3668c47003da2b5053618b02e885820b4
7
+ data.tar.gz: fdd0d44e7b5f7cc893c5dee140e679898f587e2859b9cfa26d01d80e907ad28e8eb228f7346a924b18a96b273327c24ed8b8926e45f449b21750b9aa125573a4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diml (0.1.0)
4
+ diml (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,6 +10,7 @@ GEM
10
10
  coderay (1.1.3)
11
11
  json (2.6.2)
12
12
  method_source (1.0.0)
13
+ minitest (5.16.3)
13
14
  parallel (1.22.1)
14
15
  parser (3.1.2.0)
15
16
  ast (~> 2.4.1)
@@ -40,6 +41,7 @@ PLATFORMS
40
41
 
41
42
  DEPENDENCIES
42
43
  diml!
44
+ minitest
43
45
  pry
44
46
  rake (~> 13.0)
45
47
  rubocop (~> 1.21)
data/Makefile CHANGED
@@ -6,6 +6,9 @@ console:
6
6
  setup:
7
7
  @bundle exec bin/setup
8
8
 
9
+ build:
10
+ @bundle exec rake build
11
+
9
12
  install:
10
13
  @bundle exec rake install
11
14
 
data/diml.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["aquaflamingo"]
9
9
  spec.email = ["16901597+aquaflamingo@users.noreply.github.com"]
10
10
 
11
- spec.summary = "Sum"
12
- spec.description = "Desc"
11
+ spec.summary = "Convert a diml document to markdown"
12
+ spec.description = "A diml document provides a simple markup format for dictating notes in a way to preserve formatting for transformation to a presentable format (e.g. markdown)"
13
13
  spec.homepage = "https://github.com/aquaflamingo/diml"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  # Uncomment to register a new dependency of your gem
33
33
  # spec.add_dependency "example-gem", "~> 1.0"
34
34
  spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "minitest"
35
36
 
36
37
  # For more information and examples about making a new gem, check out our
37
38
  # guide at: https://bundler.io/guides/creating_gem.html
data/examples/parse_md.rb CHANGED
@@ -28,7 +28,12 @@ OptionParser.new do |parser|
28
28
  end.parse!
29
29
 
30
30
  def diml_to_md(input)
31
- doc = Diml::Document.load(input)
31
+ begin
32
+ doc = Diml::Document.load(input)
33
+ rescue => e
34
+ puts "failed to parse: #{e.message}"
35
+ exit 1
36
+ end
32
37
 
33
38
  formatter = Diml::Formatter.new(doc, :markdown)
34
39
 
@@ -4,100 +4,113 @@ require_relative "../elements/factory.rb"
4
4
  require_relative "../elements/section"
5
5
  require_relative "../elements/point"
6
6
  require_relative "../elements/heading"
7
+ require_relative "../error"
7
8
 
8
9
  # Basic document parser
9
10
  module Diml
10
- class Parser
11
- def initialize(raw_content)
12
- @raw_content = raw_content
13
- end
14
-
15
- # Parses the raw content for a DIML document into
16
- # the internal representation.
17
- def parse
18
- basic_tokens = @raw_content.split(";")
19
-
20
- # Create new Content Tree
21
- ctree = ContentTree.new
22
- ctree.content = Root.new("")
23
- ctree.root!
24
-
25
- tree = build_tree(ctree, basic_tokens)
26
11
 
27
- # Return the root not the last value
28
- t = tree
29
- t = t.parent until t.root?
30
- t
31
- end
32
-
33
- private
34
-
35
- # Recursive content tree builder
36
- def build_tree(ctree, tokens)
37
- # Basic case: if there are no nestable tokens
38
- return ctree if tokens.empty?
12
+ #
13
+ # Parser is responsible for converted raw content into a DiML document tree
14
+ #
15
+ class Parser
16
+ def initialize(raw_content)
17
+ @raw_content = raw_content
18
+ end
39
19
 
40
- # Pull first element from the start of the array
41
- next_token = tokens.first.strip
42
- tokens = tokens.drop(1)
20
+ # Parses the raw content for a DIML document into
21
+ # the internal representation.
22
+ def parse
23
+ basic_tokens = @raw_content.split(";")
43
24
 
44
- # Create a new element
45
- element = Factory.new_element(next_token)
25
+ # Create new Content Tree
26
+ ctree = ContentTree.new
27
+ ctree.content = Root.new("")
28
+ ctree.root!
46
29
 
47
- case element.class.name
48
- when Section.name
49
- if ctree.root?
50
- # Sections can only belong as children to the root.
51
- child = add_to_tree(ctree, element)
52
- else
53
- # Continue to traverse upwards until you find the root
54
- ancestor = ctree.parent
55
- ancestor = ancestor.parent until ancestor.root?
30
+ tree = build_tree(ctree, basic_tokens)
56
31
 
57
- # Ancestor is root. Insert this section.
58
- child = add_to_tree(ancestor, element)
59
- end
32
+ # Return the root not the last value
33
+ t = tree
34
+ t = t.parent until t.root?
35
+ t
36
+ end
60
37
 
61
- build_tree(child, tokens)
62
- when Heading.name
63
- if ctree.content.instance_of? Section
64
- # Headings can only belong to sections
65
- child = add_to_tree(ctree, element)
66
- else
67
- ancestor = ctree.parent
68
- ancestor = ancestor.parent until ancestor.content.instance_of? Section
69
-
70
- # Ancestor is root. Insert this section.
71
- child = add_to_tree(ancestor, element)
38
+ private
39
+
40
+ # Recursive content tree builder
41
+ def build_tree(ctree, tokens)
42
+ # Basic case: if there are no nestable tokens
43
+ return ctree if tokens.empty?
44
+
45
+ # Pull first element from the start of the array
46
+ next_token = tokens.first.strip
47
+ tokens = tokens.drop(1)
48
+
49
+ # Create a new element
50
+ element = Factory.new_element(next_token)
51
+
52
+ case element.class.name
53
+ when Section.name
54
+ if ctree.root?
55
+ # Sections can only belong as children to the root.
56
+ child = add_to_tree(ctree, element)
57
+ else
58
+ # Continue to traverse upwards until you find the root
59
+ ancestor = ctree.parent
60
+ ancestor = ancestor.parent until ancestor.root?
61
+
62
+ # Ancestor is root. Insert this section.
63
+ child = add_to_tree(ancestor, element)
64
+ end
65
+
66
+ build_tree(child, tokens)
67
+ when Heading.name
68
+ if ctree.content.instance_of? Section
69
+ # Headings can only belong to sections
70
+ child = add_to_tree(ctree, element)
71
+ else
72
+ begin
73
+ ancestor = ctree.parent
74
+ ancestor = ancestor.parent until ancestor.content.instance_of? Section
75
+ rescue => e
76
+ raise DocumentError.new("invalid diml document: heading must be child of section")
77
+ end
78
+
79
+ # Ancestor is root. Insert this section.
80
+ child = add_to_tree(ancestor, element)
81
+ end
82
+
83
+ build_tree(child, tokens)
84
+ when Point.name
85
+ if ctree.content.instance_of? Heading
86
+ # Headings can only belong to sections
87
+ child = add_to_tree(ctree, element)
88
+ else
89
+ begin
90
+ ancestor = ctree.parent
91
+ ancestor = ancestor.parent until ancestor.content.instance_of? Heading
92
+ rescue => e
93
+ raise DocumentError.new("invalid diml document: point must be child of heading")
94
+ end
95
+
96
+ # Ancestor is root. Insert this section.
97
+ child = add_to_tree(ancestor, element)
98
+ end
99
+
100
+ build_tree(child, tokens)
72
101
  end
73
102
 
74
- build_tree(child, tokens)
75
- when Point.name
76
- if ctree.content.instance_of? Heading
77
- # Headings can only belong to sections
78
- child = add_to_tree(ctree, element)
79
- else
80
- ancestor = ctree.parent
81
- ancestor = ancestor.parent until ancestor.content.instance_of? Heading
82
-
83
- # Ancestor is root. Insert this section.
84
- child = add_to_tree(ancestor, element)
85
- end
86
-
87
- build_tree(child, tokens)
103
+ ctree
88
104
  end
89
105
 
90
- ctree
91
- end
106
+ # Helper method to create and add a new element to a content tree
107
+ def add_to_tree(tree, child_element)
108
+ child = ContentTree.new
109
+ child.parent = tree
110
+ child.content = child_element
111
+ tree.add_child(child)
92
112
 
93
- # Helper method to create and add a new element to a content tree
94
- def add_to_tree(tree, child_element)
95
- child = ContentTree.new
96
- child.parent = tree
97
- child.content = child_element
98
- tree.add_child(child)
99
-
100
- child
113
+ child
114
+ end
101
115
  end
102
116
  end
103
- end
data/lib/diml/error.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Diml
2
+ class DocumentError < StandardError; end
3
+ end
data/lib/diml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diml
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aquaflamingo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -24,7 +24,22 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Desc
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A diml document provides a simple markup format for dictating notes in
42
+ a way to preserve formatting for transformation to a presentable format (e.g. markdown)
28
43
  email:
29
44
  - 16901597+aquaflamingo@users.noreply.github.com
30
45
  executables:
@@ -61,6 +76,7 @@ files:
61
76
  - lib/diml/elements/point.rb
62
77
  - lib/diml/elements/root.rb
63
78
  - lib/diml/elements/section.rb
79
+ - lib/diml/error.rb
64
80
  - lib/diml/format/formatter.rb
65
81
  - lib/diml/format/markdown.rb
66
82
  - lib/diml/version.rb
@@ -90,5 +106,5 @@ requirements: []
90
106
  rubygems_version: 3.3.7
91
107
  signing_key:
92
108
  specification_version: 4
93
- summary: Sum
109
+ summary: Convert a diml document to markdown
94
110
  test_files: []