codeless_code 0.1.8 → 0.2.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.
- checksums.yaml +4 -4
- data/.gitmodules +1 -1
- data/.reek.yml +2 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/Guardfile +15 -13
- data/VERSION +1 -1
- data/codeless_code.gemspec +11 -10
- data/data/the-codeless-code/de-andrebogus/case-193.txt +1 -1
- data/data/the-codeless-code/de-andrebogus/case-74.txt +1 -1
- data/data/the-codeless-code/en-qi/case-194.txt +1 -1
- data/data/the-codeless-code/en-qi/case-74.txt +1 -1
- data/lib/codeless_code/cli.rb +1 -1
- data/lib/codeless_code/fable.rb +1 -1
- data/lib/codeless_code/formats/base.rb +2 -19
- data/lib/codeless_code/formats/plain.rb +34 -21
- data/lib/codeless_code/formats/term.rb +48 -18
- data/lib/codeless_code/markup/converter.rb +78 -0
- data/lib/codeless_code/markup/nodes.rb +64 -0
- data/lib/codeless_code/markup/parser.rb +152 -0
- data/lib/codeless_code/renderers/term_page.rb +1 -1
- data/lib/codeless_code.rb +7 -7
- data/test/codeless_code/filters/{test_langs.rb → test_lang.rb} +0 -0
- data/test/codeless_code/formats/test_plain.rb +74 -0
- data/{lib/codeless_code/formats/parsers/plain.rb → test/codeless_code/formats/test_raw.rb} +6 -28
- data/test/codeless_code/formats/test_term.rb +72 -0
- data/test/codeless_code/markup/test_parser.rb +177 -0
- data/test/codeless_code/test_cli.rb +75 -2
- data/test/support/fs.rb +15 -0
- metadata +10 -20
- data/lib/codeless_code/formats/parsers/base.rb +0 -106
- data/lib/codeless_code/formats/parsers/term.rb +0 -79
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeless_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Sangster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.8'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: mediacloth
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.6'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.6'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: nokogiri
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -1763,13 +1749,13 @@ files:
|
|
1763
1749
|
- lib/codeless_code/filters/lang.rb
|
1764
1750
|
- lib/codeless_code/filters/translator.rb
|
1765
1751
|
- lib/codeless_code/formats/base.rb
|
1766
|
-
- lib/codeless_code/formats/parsers/base.rb
|
1767
|
-
- lib/codeless_code/formats/parsers/plain.rb
|
1768
|
-
- lib/codeless_code/formats/parsers/term.rb
|
1769
1752
|
- lib/codeless_code/formats/plain.rb
|
1770
1753
|
- lib/codeless_code/formats/raw.rb
|
1771
1754
|
- lib/codeless_code/formats/term.rb
|
1772
1755
|
- lib/codeless_code/language_set.rb
|
1756
|
+
- lib/codeless_code/markup/converter.rb
|
1757
|
+
- lib/codeless_code/markup/nodes.rb
|
1758
|
+
- lib/codeless_code/markup/parser.rb
|
1773
1759
|
- lib/codeless_code/options.rb
|
1774
1760
|
- lib/codeless_code/renderers/fable.rb
|
1775
1761
|
- lib/codeless_code/renderers/term_page.rb
|
@@ -1779,8 +1765,12 @@ files:
|
|
1779
1765
|
- test/codeless_code/filters/test_builders.rb
|
1780
1766
|
- test/codeless_code/filters/test_composite.rb
|
1781
1767
|
- test/codeless_code/filters/test_date.rb
|
1782
|
-
- test/codeless_code/filters/
|
1768
|
+
- test/codeless_code/filters/test_lang.rb
|
1783
1769
|
- test/codeless_code/filters/test_translator.rb
|
1770
|
+
- test/codeless_code/formats/test_plain.rb
|
1771
|
+
- test/codeless_code/formats/test_raw.rb
|
1772
|
+
- test/codeless_code/formats/test_term.rb
|
1773
|
+
- test/codeless_code/markup/test_parser.rb
|
1784
1774
|
- test/codeless_code/renderers/test_fable.rb
|
1785
1775
|
- test/codeless_code/renderers/test_term_page.rb
|
1786
1776
|
- test/codeless_code/test_catalog.rb
|
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# codeless_code filters and prints fables from http://thecodelesscode.com
|
4
|
-
# Copyright (C) 2018 Jon Sangster
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify it under
|
7
|
-
# the terms of the GNU General Public License as published by the Free Software
|
8
|
-
# Foundation, either version 3 of the License, or (at your option) any later
|
9
|
-
# version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14
|
-
# details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License along with
|
17
|
-
# this program. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
require 'mediacloth'
|
19
|
-
|
20
|
-
module CodelessCode
|
21
|
-
module Formats
|
22
|
-
module Parsers
|
23
|
-
# An abstract base class for the custom parsers for the syntax tree
|
24
|
-
# generated by the +MediaCloth+ gem.
|
25
|
-
class Base < MediaWikiWalker
|
26
|
-
# Reimplement these
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# def parse_paragraph(ast)
|
30
|
-
# parse_wiki_ast(ast)
|
31
|
-
# end
|
32
|
-
ABSTRACT_METHODS = %i[
|
33
|
-
parse_paragraph
|
34
|
-
parse_paste
|
35
|
-
parse_formatted
|
36
|
-
parse_list_item
|
37
|
-
parse_list_term
|
38
|
-
parse_list_definition
|
39
|
-
parse_preformatted
|
40
|
-
parse_section
|
41
|
-
parse_link
|
42
|
-
parse_internal_link
|
43
|
-
parse_internal_link_item
|
44
|
-
parse_table
|
45
|
-
parse_table_row
|
46
|
-
parse_table_cell
|
47
|
-
parse_element
|
48
|
-
parse_template
|
49
|
-
parse_category
|
50
|
-
parse_keyword
|
51
|
-
].freeze
|
52
|
-
|
53
|
-
attr_reader :ctx
|
54
|
-
|
55
|
-
def initialize(ctx)
|
56
|
-
@ctx = ctx
|
57
|
-
end
|
58
|
-
|
59
|
-
protected
|
60
|
-
|
61
|
-
def parse_wiki_ast(ast)
|
62
|
-
super(ast).join
|
63
|
-
end
|
64
|
-
|
65
|
-
ABSTRACT_METHODS.each do |meth|
|
66
|
-
define_method(meth) { |ast| parse_wiki_ast(ast) }
|
67
|
-
end
|
68
|
-
|
69
|
-
# Reimplement this
|
70
|
-
# :reek:UtilityFunction
|
71
|
-
def parse_text(ast)
|
72
|
-
ast.contents
|
73
|
-
end
|
74
|
-
|
75
|
-
# Reimplement this
|
76
|
-
def parse_list(ast)
|
77
|
-
ast.children.map(&method(:parse_list_child))
|
78
|
-
end
|
79
|
-
|
80
|
-
# Reimplement this
|
81
|
-
def parse_resource_link(ast)
|
82
|
-
ast.children.map do |child|
|
83
|
-
parse_internal_link_item(child) if child.is_a?(InternalLinkItemAST)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Reimplement this
|
88
|
-
def parse_category_link(ast)
|
89
|
-
ast.children.map do |child|
|
90
|
-
parse_internal_link_item(child) if child.is_a?(InternalLinkItemAST)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
def parse_list_child(child)
|
97
|
-
case child
|
98
|
-
when ListItemAST then parse_list_item(child)
|
99
|
-
when ListTermAST then parse_list_term(child)
|
100
|
-
when ListDefinitionAST then parse_list_definition(child)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# codeless_code filters and prints fables from http://thecodelesscode.com
|
4
|
-
# Copyright (C) 2018 Jon Sangster
|
5
|
-
#
|
6
|
-
# This program is free software: you can redistribute it and/or modify it under
|
7
|
-
# the terms of the GNU General Public License as published by the Free Software
|
8
|
-
# Foundation, either version 3 of the License, or (at your option) any later
|
9
|
-
# version.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14
|
-
# details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License along with
|
17
|
-
# this program. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
require 'mediacloth'
|
19
|
-
|
20
|
-
module CodelessCode
|
21
|
-
module Formats
|
22
|
-
module Parsers
|
23
|
-
# A custom parser for the syntax tree generated by the +MediaCloth+ gem
|
24
|
-
# which formats a document using ANSI codes for color, bold, italics, and
|
25
|
-
# other styles.
|
26
|
-
class Term < Base
|
27
|
-
protected
|
28
|
-
|
29
|
-
def parse_formatted(ast)
|
30
|
-
if ast.formatting == :Bold
|
31
|
-
color(parse_wiki_ast(ast)).bold
|
32
|
-
else
|
33
|
-
color(parse_wiki_ast(ast)).italic
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def parse_preformatted(ast)
|
38
|
-
color(parse_wiki_ast(ast)).green
|
39
|
-
end
|
40
|
-
|
41
|
-
def parse_section(ast)
|
42
|
-
color(parse_wiki_ast(ast).strip).blue
|
43
|
-
end
|
44
|
-
|
45
|
-
def parse_link(ast)
|
46
|
-
color(parse_wiki_ast(ast)).underline
|
47
|
-
end
|
48
|
-
|
49
|
-
def parse_internal_link(ast)
|
50
|
-
text = parse_wiki_ast(ast)
|
51
|
-
color(!text.empty? ? text : ast.locator).underline
|
52
|
-
end
|
53
|
-
|
54
|
-
def parse_element(ast)
|
55
|
-
str = parse_wiki_ast(ast)
|
56
|
-
if ast.name == 'pre'
|
57
|
-
color(ctx.generate(str.gsub(/\A\n*(.*?)\n*\z/m, '\1'))).red
|
58
|
-
else
|
59
|
-
str
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def parse_template(ast)
|
64
|
-
color(ast.template_name).yellow
|
65
|
-
end
|
66
|
-
|
67
|
-
def parse_keyword(ast)
|
68
|
-
color(parse_wiki_ast(ast)).underline
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def color(str)
|
74
|
-
ctx.color(str)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|