codeless_code 0.1.4 → 0.1.5

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: bc18a71aa3e43895db1c702116523d456e8f583efcb341e4c8eb74d7a764a22e
4
- data.tar.gz: '05595e53a98c72b33a7d776bdd4f5795ba608d7c6b333b6d6cc6b67308e57828'
3
+ metadata.gz: 9db33a7d878ec62fe6764ac8c19e36c54e79b27bd6a5a27c74c2ddf3ac339105
4
+ data.tar.gz: 02c2096353f43e96970ab65b9f38de50f0f27cb3c4e018cb4beae317241c29eb
5
5
  SHA512:
6
- metadata.gz: a884f539c917ad7d2c9e1a1aac1b11a29abd8f28c4a9cb0d5418cc3a7f9c7602e11ff2d962b796557dce82a4e85e84d350224f18ecefc3e07f87d0c55317c37b
7
- data.tar.gz: 4000cd5a1e2613e04c0525fdd382b4c779e4b381b6c90d5b06a805935d545529793358d47794ae58851b215a4412983f6fa4894554ccf02f2c8731d2a0b99527
6
+ metadata.gz: 11f14612021cd8c058a288094f8da15aebc7468406eae664c2f9a92a79f444b2fda2fd2b9e608b7ba57b38c29ef0a64a6c1c7e418369753874ceeb4489423b9e
7
+ data.tar.gz: 6c1c83e013f53e93494a92b18a0c2348eeda737d095b4598dd5dde37ca32a2b44b4f04da2e7a8099726801c186f3fbe460564ce93778ed2873fecfac06098e55
data/README.md CHANGED
@@ -33,11 +33,12 @@ codeless_code -h # get help
33
33
  There are different translations available, but different people
34
34
 
35
35
  ```sh
36
+ codeless_code -p /some/dir # source the fables from a different folder
36
37
  codeless_code --list-translations # see what languages you can use
37
38
  codeless_code -L zh # list fables translated into Chinese
38
39
  codeless_code -L ru -R edro # list fables translated into Russian by edro
39
40
 
40
- codeless_code -L fr --daily # Print today's French fable
41
+ codeless_code -L fr --daily # print today's French fable
41
42
  ```
42
43
 
43
44
  ### Filtering
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: codeless_code 0.1.4 ruby lib
5
+ # stub: codeless_code 0.1.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "codeless_code".freeze
9
- s.version = "0.1.4"
9
+ s.version = "0.1.5"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -1492,6 +1492,8 @@ Gem::Specification.new do |s|
1492
1492
  "lib/codeless_code/filters/lang.rb",
1493
1493
  "lib/codeless_code/filters/translator.rb",
1494
1494
  "lib/codeless_code/formats/base.rb",
1495
+ "lib/codeless_code/formats/plain.rb",
1496
+ "lib/codeless_code/formats/plain_generator.rb",
1495
1497
  "lib/codeless_code/formats/raw.rb",
1496
1498
  "lib/codeless_code/formats/term.rb",
1497
1499
  "lib/codeless_code/formats/term_generator.rb",
@@ -70,8 +70,9 @@ module CodelessCode
70
70
 
71
71
  def output_format
72
72
  case options[:format]
73
- when 'raw' then Formats::Raw
74
- else Formats::Term
73
+ when 'plain' then Formats::Plain
74
+ when 'raw' then Formats::Raw
75
+ else Formats::Term
75
76
  end
76
77
  end
77
78
 
@@ -95,7 +96,7 @@ module CodelessCode
95
96
  end
96
97
 
97
98
  def version_str
98
- format("%s %s\n\n%s\n\nSee <%s>", @command_name, VERSION,
99
+ format(['%s %s', '%s', 'See <%s>'].join("\n\n"), @command_name, VERSION,
99
100
  copyright_summary, 'https://github.com/sangster/codeless_code')
100
101
  end
101
102
 
@@ -13,6 +13,9 @@
13
13
  #
14
14
  # You should have received a copy of the GNU General Public License along with
15
15
  # this program. If not, see <https://www.gnu.org/licenses/>.
16
+ require 'mediacloth'
17
+ require 'nokogiri'
18
+
16
19
  module CodelessCode
17
20
  module Formats
18
21
  class Base
@@ -24,7 +27,14 @@ module CodelessCode
24
27
 
25
28
  protected
26
29
 
27
- def formatted
30
+ def to_xhtml(str)
31
+ # MediaCloth expects XHTML-ish pages and chokes on ommited end tags
32
+ Nokogiri::HTML(str).css('body > *').to_xhtml
33
+ end
34
+
35
+ def from_wiki(str, generator)
36
+ return "" if str.length == 0
37
+ MediaCloth::wiki_to_html(str, generator: generator)
28
38
  end
29
39
  end
30
40
  end
@@ -0,0 +1,44 @@
1
+ # codeless_code filters and prints fables from http://thecodelesscode.com
2
+ # Copyright (C) 2018 Jon Sangster
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU General Public License as published by the Free Software
6
+ # Foundation, either version 3 of the License, or (at your option) any later
7
+ # version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful, but WITHOUT
10
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ # details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along with
15
+ # this program. If not, see <https://www.gnu.org/licenses/>.
16
+ require 'mediacloth'
17
+
18
+ module CodelessCode
19
+ module Formats
20
+ class Plain < Base
21
+ def call
22
+ raw.split("\n\n")
23
+ .map { |str| from_wiki(to_xhtml(regex(str))) }
24
+ .join("\n\n")
25
+ end
26
+
27
+ private
28
+
29
+ def regex(str)
30
+ [
31
+ [/\/\/\w*$/, ''],
32
+ [/<i>([^<]+)<\/i>/mi, '\1'],
33
+ [/<b>([^<]+)<\/b>/mi, '\1'],
34
+ [/<a[^>]+>([^<]+)<\/a>/mi, '\1'],
35
+ [/\/(\w+)\//, '\1'],
36
+ ].inject(str) { |str, args| str = str.gsub(*args) }
37
+ end
38
+
39
+ def from_wiki(str)
40
+ super(str, PlainGenerator.new(self))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,157 @@
1
+ # codeless_code filters and prints fables from http://thecodelesscode.com
2
+ # Copyright (C) 2018 Jon Sangster
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU General Public License as published by the Free Software
6
+ # Foundation, either version 3 of the License, or (at your option) any later
7
+ # version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful, but WITHOUT
10
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ # details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along with
15
+ # this program. If not, see <https://www.gnu.org/licenses/>.
16
+ require 'mediacloth'
17
+
18
+ module CodelessCode
19
+ module Formats
20
+ class PlainGenerator < MediaWikiWalker
21
+ def initialize(ctx)
22
+ @ctx = ctx
23
+ end
24
+
25
+ protected
26
+
27
+ def parse_wiki_ast(ast)
28
+ super(ast).join
29
+ end
30
+
31
+ #Reimplement this
32
+ def parse_paragraph(ast)
33
+ parse_wiki_ast(ast)
34
+ end
35
+
36
+ #Reimplement this
37
+ def parse_paste(ast)
38
+ parse_wiki_ast(ast)
39
+ end
40
+
41
+ #Reimplement this
42
+ def parse_formatted(ast)
43
+ parse_wiki_ast(ast)
44
+ end
45
+
46
+ #Reimplement this
47
+ def parse_text(ast)
48
+ ast.contents
49
+ end
50
+
51
+ #Reimplement this
52
+ def parse_list(ast)
53
+ ast.children.map do |c|
54
+ r = parse_list_item(c) if c.class == ListItemAST
55
+ r = parse_list_term(c) if c.class == ListTermAST
56
+ r = parse_list_definition(c) if c.class == ListDefinitionAST
57
+ r
58
+ end
59
+ end
60
+
61
+ #Reimplement this
62
+ def parse_list_item(ast)
63
+ parse_wiki_ast(ast)
64
+ end
65
+
66
+ #Reimplement this
67
+ def parse_list_term(ast)
68
+ parse_wiki_ast(ast)
69
+ end
70
+
71
+ #Reimplement this
72
+ def parse_list_definition(ast)
73
+ parse_wiki_ast(ast)
74
+ end
75
+
76
+ #Reimplement this
77
+ def parse_preformatted(ast)
78
+ parse_wiki_ast(ast)
79
+ end
80
+
81
+ #Reimplement this
82
+ def parse_section(ast)
83
+ parse_wiki_ast(ast).strip
84
+ end
85
+
86
+ #Reimplement this
87
+ def parse_link(ast)
88
+ parse_wiki_ast(ast)
89
+ end
90
+
91
+ #Reimplement this
92
+ def parse_internal_link(ast)
93
+ text = parse_wiki_ast(ast)
94
+ text.size > 0 ? text : ast.locator
95
+ end
96
+
97
+ #Reimplement this
98
+ def parse_resource_link(ast)
99
+ ast.children.map do |c|
100
+ parse_internal_link_item(c) if c.class == InternalLinkItemAST
101
+ end
102
+ end
103
+
104
+ #Reimplement this
105
+ def parse_category_link(ast)
106
+ ast.children.map do |c|
107
+ parse_internal_link_item(c) if c.class == InternalLinkItemAST
108
+ end
109
+ end
110
+
111
+ #Reimplement this
112
+ def parse_internal_link_item(ast)
113
+ parse_wiki_ast(ast)
114
+ end
115
+
116
+ #Reimplement this
117
+ def parse_table(ast)
118
+ parse_wiki_ast(ast)
119
+ end
120
+
121
+ #Reimplement this
122
+ def parse_table_row(ast)
123
+ parse_wiki_ast(ast)
124
+ end
125
+
126
+ #Reimplement this
127
+ def parse_table_cell(ast)
128
+ parse_wiki_ast(ast)
129
+ end
130
+
131
+ #Reimplement this
132
+ def parse_element(ast)
133
+ str = parse_wiki_ast(ast)
134
+ if ast.name == 'pre'
135
+ @ctx.generate(str.gsub(/\A\n*(.*?)\n*\z/m, '\1'))
136
+ else
137
+ str
138
+ end
139
+ end
140
+
141
+ #Reimplement this
142
+ def parse_template(ast)
143
+ ast.template_name
144
+ end
145
+
146
+ #Reimplement this
147
+ def parse_category(ast)
148
+ raise NotImplementedError
149
+ end
150
+
151
+ #Reimplement this
152
+ def parse_keyword(ast)
153
+ parse_wiki_ast(ast)
154
+ end
155
+ end
156
+ end
157
+ end
@@ -22,15 +22,10 @@ module CodelessCode
22
22
  class Term < Base
23
23
  def call
24
24
  raw.split("\n\n")
25
- .map { |str| generate(to_xhtml(regex(str))) }
25
+ .map { |str| from_wiki(to_xhtml(regex(str))) }
26
26
  .join("\n\n")
27
27
  end
28
28
 
29
- def to_xhtml(str)
30
- # MediaCloth expects XHTML-ish pages and chokes on ommited end tags
31
- Nokogiri::HTML(str).css('body > *').to_xhtml
32
- end
33
-
34
29
  def regex(str)
35
30
  [
36
31
  [/\/\/\w*$/, ''],
@@ -42,9 +37,8 @@ module CodelessCode
42
37
  ].inject(str) { |str, args| str = str.gsub(*args) }
43
38
  end
44
39
 
45
- def generate(str)
46
- return "" if str.length == 0
47
- MediaCloth::wiki_to_html(str, generator: TermGenerator.new(self))
40
+ def from_wiki(str)
41
+ super(str, TermGenerator.new(self))
48
42
  end
49
43
 
50
44
  def c(str)
data/lib/codeless_code.rb CHANGED
@@ -30,10 +30,12 @@ module CodelessCode
30
30
  end
31
31
 
32
32
  module Formats
33
- autoload :Base, 'codeless_code/formats/base'
34
- autoload :Raw, 'codeless_code/formats/raw'
35
- autoload :Term, 'codeless_code/formats/term'
36
- autoload :TermGenerator, 'codeless_code/formats/term_generator'
33
+ autoload :Base, 'codeless_code/formats/base'
34
+ autoload :Plain, 'codeless_code/formats/plain'
35
+ autoload :PlainGenerator, 'codeless_code/formats/plain_generator'
36
+ autoload :Raw, 'codeless_code/formats/raw'
37
+ autoload :Term, 'codeless_code/formats/term'
38
+ autoload :TermGenerator, 'codeless_code/formats/term_generator'
37
39
  end
38
40
 
39
41
  module Renderers
@@ -67,7 +69,7 @@ module CodelessCode
67
69
  o.separator ''
68
70
  o.separator 'Options'
69
71
  o.string '-o', '--output', 'write to the given file. "-" for STDOUT'
70
- o.string '-f', '--format', 'one of: raw, term (default)'
72
+ o.string '-f', '--format', 'one of: raw, plain, or term (default)'
71
73
  o.string '-p', '--path', 'path to directory of fables. ' \
72
74
  'see github.com/aldesantis/the-codeless-code'
73
75
  o.boolean '--random', 'select one fable, randomly, from the filtered list'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeless_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Sangster
@@ -1718,6 +1718,8 @@ files:
1718
1718
  - lib/codeless_code/filters/lang.rb
1719
1719
  - lib/codeless_code/filters/translator.rb
1720
1720
  - lib/codeless_code/formats/base.rb
1721
+ - lib/codeless_code/formats/plain.rb
1722
+ - lib/codeless_code/formats/plain_generator.rb
1721
1723
  - lib/codeless_code/formats/raw.rb
1722
1724
  - lib/codeless_code/formats/term.rb
1723
1725
  - lib/codeless_code/formats/term_generator.rb