wikitree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12e6f4b45852b8848548302d88125c753fb89e1a
4
+ data.tar.gz: e0fbb8c39bf9b113ccf8310e57acb450d6ad2106
5
+ SHA512:
6
+ metadata.gz: 2a020809e8b0267805a62e361e1d131c1323c78d094498c11ea2dddb9ebf8bb948ac32110ce120508d9775059b01e1ad4431694e9dc607ea91b056175d94991d
7
+ data.tar.gz: 31d70b43cc4bb0b4f07d538f1442e338e22c5c62593fb0d5e29b6f88f76f694d3955962f485b51386f9a52954dd5618b2b732c0fca93afd5da37c4472ff88cc9
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2020-11-30
2
+
3
+ * Everything is new. First release.
@@ -0,0 +1,9 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/wikitree.rb
6
+ lib/wikitree/nodes.rb
7
+ lib/wikitree/version.rb
8
+ test/helper.rb
9
+ test/test_nodes.rb
@@ -0,0 +1,32 @@
1
+ # Wikitree - Wikitext/script Abstract Syntax Tree (AST)
2
+
3
+
4
+ * home :: [github.com/wikiscript/wikiscript](https://github.com/wikiscript/wikiscript)
5
+ * bugs :: [github.com/wikiscript/wikiscript/issues](https://github.com/wikiscript/wikiscript/issues)
6
+ * gem :: [rubygems.org/gems/wikitree](https://rubygems.org/gems/wikitree)
7
+ * rdoc :: [rubydoc.info/gems/wikitree](http://rubydoc.info/gems/wikitree)
8
+
9
+
10
+ ## Usage
11
+
12
+
13
+ to be done
14
+
15
+
16
+
17
+
18
+ ## Install
19
+
20
+ Use
21
+
22
+ gem install wikitree
23
+
24
+ or add to your Gemfile
25
+
26
+ gem 'wikitree'
27
+
28
+
29
+ ## License
30
+
31
+ The `wikiscript` scripts are dedicated to the public domain.
32
+ Use it as you please with no restrictions whatsoever.
@@ -0,0 +1,27 @@
1
+ require 'hoe'
2
+ require './lib/wikitree/version.rb'
3
+
4
+ Hoe.spec 'wikitree' do
5
+
6
+ self.version = Wikiscript::Module::Tree::VERSION
7
+
8
+ self.summary = "wikitree - wikitext/script abstract syntax tree (ast)"
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/wikiscript/wikiscript' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'opensport@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = []
21
+
22
+ self.licenses = ['Public Domain']
23
+
24
+ self.spec_extras = {
25
+ required_ruby_version: '>= 2.2.2'
26
+ }
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'pp'
2
+
3
+
4
+ # our own code
5
+ require 'wikitree/version' # let it always go first
6
+ require 'wikitree/nodes'
7
+
8
+
9
+
10
+ ## add camelcase alias
11
+ WikiTree = Wikitree
12
+
13
+
14
+ puts Wikiscript::Module::Tree.banner
@@ -0,0 +1,169 @@
1
+ ###
2
+ # a little abstract syntax tree for wikitext/script
3
+
4
+ module Wikitree
5
+
6
+ class Node
7
+ end
8
+
9
+
10
+ class Text < Node ## Text run/segement
11
+ def initialize( text )
12
+ @text = text
13
+ end
14
+
15
+ def to_text
16
+ ## todo: fix remove possible html stuff - why? why not?
17
+ @text
18
+ end
19
+ def to_wiki() @text; end
20
+
21
+ def inspect
22
+ @text.inspect
23
+ end
24
+ end
25
+
26
+
27
+ class Page < Node ## wiki page link - use a different name - why? why not?
28
+ def initialize( name, alt_name=nil )
29
+ @name = name
30
+ @alt_name = alt_name
31
+ end
32
+
33
+ def to_text
34
+ text = @alt_name ? @alt_name : @name
35
+ " #{text} " ## note: wrap for now in leading and trailing space!! - fix space issue sometime!!
36
+ end
37
+ def to_wiki
38
+ if @alt_name
39
+ "[[#{@name}|#{@alt_name}]]"
40
+ else
41
+ "[[#{@name}]]"
42
+ end
43
+ end
44
+
45
+ def inspect
46
+ if @alt_name
47
+ "#<page #{@name} | #{@alt_name}>"
48
+ else
49
+ "#<page #{@name}>"
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ class Template < Node
56
+ attr_reader :name,
57
+ :params
58
+
59
+ class Param ## use a nested param class - why? why not?
60
+ attr_reader :num, ## note: starts with 1 (NOT 0)
61
+ :name,
62
+ :value
63
+ def initialize( num, name, value )
64
+ @num = num # todo/check: rename to index or such - why? why not?
65
+ @name = name
66
+ @value = value
67
+ end
68
+
69
+ def inspect
70
+ if @name
71
+ "#<_#{num} (#{@name}): #{@value.inspect}>"
72
+ else
73
+ "#<_#{num}: #{@value.inspect}>"
74
+ end
75
+ end
76
+
77
+ def pretty_print(pp)
78
+ if @name
79
+ pp.text "#<_#{num} (#{@name}): "
80
+ else
81
+ pp.text "#<_#{num}: "
82
+ end
83
+ pp.breakable
84
+ pp.pp @value
85
+ pp.text ">"
86
+ end
87
+
88
+ def to_text
89
+ if value.empty? ## note: value might be nil (convert to "")
90
+ ''
91
+ else
92
+ value.map { |node| node.to_text }.join
93
+ end
94
+ end
95
+ def to_wiki
96
+ if value.empty? ## note: value might be nil (convert to "")
97
+ ''
98
+ else
99
+ value.map { |node| node.to_wiki }.join
100
+ end
101
+ end
102
+
103
+ end ## (nested) lass Param
104
+
105
+
106
+ def initialize( name, params )
107
+ @name = name
108
+ @params = []
109
+ params.each_with_index do |param,i|
110
+ @params << Param.new( i+1, param[0], param[1] )
111
+ end
112
+ end
113
+
114
+ def inspect
115
+ "#<template #{@name}: #{@params.inspect}>"
116
+ end
117
+
118
+ def pretty_print(pp)
119
+ pp.text "#<template "
120
+ pp.text "#{name}: "
121
+ pp.breakable
122
+ pp.pp @params
123
+ pp.text ">"
124
+ end
125
+
126
+ def to_text
127
+ ## build a template method name (e.g. add _ prefix and change space to _ too)
128
+ ## and dowcase e.g. Infobox country => infobox_country
129
+ method_name = "_#{@name.downcase.gsub( ' ', '_' )}".to_sym
130
+ if respond_to?( method_name )
131
+ send( method_name ) ## todo/fix: add args too!!!
132
+ else
133
+ ## rebuild template as string
134
+ buf = String.new('')
135
+ buf << "!!{{"
136
+ buf << "#{@name}"
137
+ @params.each do |param|
138
+ buf << " | "
139
+ if param.name
140
+ buf << param.name
141
+ buf << "="
142
+ end
143
+ buf << param.to_text ## note. param.to_text ONLY returns value (NOT name incl.)
144
+ end
145
+ buf << "}}"
146
+ buf
147
+ end
148
+ end
149
+
150
+ def to_wiki
151
+ ## rebuild template as string
152
+ buf = String.new('')
153
+ buf << "{{"
154
+ buf << "#{@name}"
155
+ @params.each do |param|
156
+ buf << " | "
157
+ if param.name
158
+ buf << param.name
159
+ buf << "="
160
+ end
161
+ buf << param.to_wiki ## note. param.to_text ONLY returns value (NOT name incl.)
162
+ end
163
+ buf << "}}"
164
+ buf
165
+ end
166
+ end # class Template
167
+
168
+ end # module Wikitext
169
+
@@ -0,0 +1,17 @@
1
+
2
+ module Wikiscript
3
+ module Module
4
+ module Tree
5
+ VERSION = '0.0.1'
6
+
7
+ def self.banner
8
+ "wikitree/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
9
+ end
10
+
11
+ def self.root
12
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
13
+ end
14
+
15
+ end # module Tree
16
+ end # module Module
17
+ end # module Wikiscript
@@ -0,0 +1,9 @@
1
+ ## minitest setup
2
+ require 'minitest/autorun'
3
+
4
+
5
+ ## our own code
6
+ require 'wikitree'
7
+
8
+
9
+
@@ -0,0 +1,20 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_nodes.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+
9
+ class TestNodes < MiniTest::Test
10
+
11
+ def test_page
12
+ page = Wikitree::Page.new( 'La Florida, Chile', 'La Florida' )
13
+
14
+ assert_equal ' La Florida ', page.to_text
15
+ assert_equal '[[La Florida, Chile|La Florida]]', page.to_wiki
16
+ end
17
+
18
+ end # class TestNodes
19
+
20
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikitree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.22'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.22'
47
+ description: wikitree - wikitext/script abstract syntax tree (ast)
48
+ email: opensport@googlegroups.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - CHANGELOG.md
53
+ - Manifest.txt
54
+ - README.md
55
+ files:
56
+ - CHANGELOG.md
57
+ - Manifest.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/wikitree.rb
61
+ - lib/wikitree/nodes.rb
62
+ - lib/wikitree/version.rb
63
+ - test/helper.rb
64
+ - test/test_nodes.rb
65
+ homepage: https://github.com/wikiscript/wikiscript
66
+ licenses:
67
+ - Public Domain
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options:
71
+ - "--main"
72
+ - README.md
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.2.2
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.5.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: wikitree - wikitext/script abstract syntax tree (ast)
91
+ test_files: []