wikimindcards_directory 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: 73b1bedf5ee2d0744780b57e6d3df862defd6f55e5d6759684ca53fbab466822
4
- data.tar.gz: 2700b6ea63021cc86c34952ff87367fad7ba572446cd23641405d7780e506eaa
3
+ metadata.gz: afb809ae2f95d576731e37c163ab3c9f0fe1fc77dfc2f48eebaf76aa658144a1
4
+ data.tar.gz: 967c0729b99b3d2df41093bbca94e2e34ce2cf046dca8a56529cd7b660547de2
5
5
  SHA512:
6
- metadata.gz: 828b05b985add568247f6c873f973b0a9974f9cb1b6a1763d03cc574994fe3f62845924df2fe828316cedd68a4223ea8122bcb01975621b884ab00d864b92691
7
- data.tar.gz: 7d7a3b3acc9964fae4f4009d541938cf8085d373392898db3c4bd06fe4d60744c732f22ce432cb656c6b651772eef842bcfadca8f6dd0ced2bb317ec93275e50
6
+ metadata.gz: ccd6cee70e1487702e1bf5f3bba3147fdd005ebec2a30a97796a5d69776a9ad2854446da8d8c10b4b03ab6932b50eafe7ad394478ddb5a97c083742638f7d3e7
7
+ data.tar.gz: 7ce2a010efe0414d2e9a9627eb73f53f061aa254276df9bbe500172311dc13a4c59277679f54cf45387a59a7ea5bd9092759d5d929c1a348b20e53d9f6162a95
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -12,7 +12,9 @@ require 'martile'
12
12
 
13
13
  class WikiMindCardsDirectory
14
14
 
15
- def initialize(dir: '.')
15
+ def initialize(dir: '.', debug: false)
16
+
17
+ @dir, @debug = dir, debug
16
18
 
17
19
  # open the file if it exists
18
20
  mindwords_file = File.join(dir, 'mindwords.txt')
@@ -22,45 +24,51 @@ class WikiMindCardsDirectory
22
24
  @mw = MindWords.new(mindwords_file)
23
25
 
24
26
  # create the activeoutline document if it doesn't already exist
25
- outline_file = File.join(dir, 'outline.txt')
27
+ outline_txt = File.join(dir, 'outline.txt')
28
+ @outline_xml = File.join(dir, 'outline.xml')
26
29
 
27
- if not File.exists? outline_file then
30
+ if not File.exists? outline_txt then
28
31
 
29
32
  s = "<?polyrex-links?>\n\n" + @mw.to_outline
30
- File.write outline_file, s
33
+ File.write outline_txt, s
31
34
 
32
35
  end
33
36
 
34
- @pl = PolyrexLinks.new(outline_file)
37
+ @pl = PolyrexLinks.new(outline_txt)
35
38
 
36
39
  end
37
40
 
38
41
  end
39
42
 
40
- def edit(type=:mindwords)
43
+ def edit(type=:mindwords, title=nil)
41
44
 
42
45
  case type
43
46
  when :link
44
- linkedit()
47
+ linkedit(title)
45
48
  when :mindwords
46
49
  mindwords_edit()
47
50
  when :tree
48
51
  tree_edit()
49
- when :index
50
- indexview()
51
52
  when :card
52
- cardedit()
53
+ cardedit(title)
53
54
  end
54
55
 
55
56
  end
56
57
 
57
- # options: :mindwords, :tree, :link, :card
58
- #
59
- def update(type=:mindwords)
58
+ def update(type, title, s)
59
+
60
+ case type
61
+ when :link
62
+ linkupdate(title, s)
63
+ when :card
64
+ cardupdate(title, s)
65
+ end
60
66
 
61
67
  end
62
-
63
- def view(type=:mindwords)
68
+
69
+ # options: :mindwords, :tree, :link, :card
70
+ #
71
+ def view(type=:mindwords, title=nil)
64
72
 
65
73
  case type
66
74
  when :mindwords
@@ -72,7 +80,7 @@ class WikiMindCardsDirectory
72
80
  when :index
73
81
  indexview()
74
82
  when :card
75
- cardview()
83
+ cardview(title)
76
84
  end
77
85
 
78
86
  end
@@ -89,24 +97,54 @@ class WikiMindCardsDirectory
89
97
  kvx = if File.exists? filepath then
90
98
  Kvx.new(filepath)
91
99
  else
92
- Kvx.new({summary: {title: params['title']}, body: {md: '', url: ''}}, \
100
+ Kvx.new({summary: {title: rawtitle}, body: {md: '', url: ''}}, \
93
101
  debug: false)
94
102
  end
95
103
 
96
104
  %Q(<form action="cardupdate" method="post">
97
- <input type='hidden' name='title' value="#{params['title']}"/>
105
+ <input type='hidden' name='title' value="#{rawtitle}"/>
98
106
  <textarea name="kvxtext" cols="73" rows="17">#{kvx.to_s}</textarea>
99
107
  <input type="submit" value="apply"/>
100
108
  </form>
101
109
  )
102
110
  end
103
111
 
112
+ def cardupdate(rawtitle, rawkvxtext)
113
+
114
+ title = rawtitle.downcase.gsub(/ +/,'-')
115
+ kvx = Kvx.new rawkvxtext.gsub(/\r/,'')
116
+
117
+ file = title + '.txt'
118
+ filepath = File.join(@dir, file)
119
+
120
+ kvx.save filepath
121
+
122
+ found = @pl.find_all_by_link_title rawtitle
123
+
124
+ found.each do |link|
125
+
126
+ url = if kvx.body[:url].length > 1 then
127
+ kvx.body[:url]
128
+ else
129
+ '/do/activeoutline/viewcard?title=' + rawtitle
130
+ end
131
+
132
+ link.url = url
133
+
134
+ end
135
+
136
+ @pl.save @outline_xml
137
+
138
+ end
139
+
104
140
  def cardview(rawtitle)
105
141
 
142
+ puts 'rawtitle: ' + rawtitle.inspect if @debug
106
143
  title = rawtitle.downcase.gsub(/ +/,'-')
107
144
 
108
145
  file = title + '.txt'
109
146
  filepath = File.join(@dir, file)
147
+ puts 'filepath: ' + filepath.inspect if @debug
110
148
 
111
149
  kvx = if File.exists? filepath then
112
150
  Kvx.new(filepath)
@@ -115,6 +153,8 @@ class WikiMindCardsDirectory
115
153
  debug: false)
116
154
  end
117
155
 
156
+ puts 'kvx: ' + kvx.inspect if @debug
157
+
118
158
  html = if kvx.body[:md].is_a? Hash then
119
159
  Kramdown::Document.new(Martile.new(kvx.body[:md][:description].to_s)\
120
160
  .to_html).to_html
@@ -144,6 +184,16 @@ class WikiMindCardsDirectory
144
184
 
145
185
  end
146
186
 
187
+ def linkupdate(rawtitle, rawurl)
188
+
189
+ r = @pl.find_by_link_title rawtitle
190
+ return unless r
191
+
192
+ r.url = rawurl
193
+ @pl.save @outline_xml
194
+
195
+ end
196
+
147
197
  def indexview()
148
198
 
149
199
  a = @pl.index
@@ -221,4 +271,3 @@ ul li {background-color: transparent; margin: 0.1em 0.1em; padding: 0.3em 0.3em}
221
271
  end
222
272
 
223
273
  end
224
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikimindcards_directory
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
  - James Robertson
metadata.gz.sig CHANGED
Binary file