mymedia-pages 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/mymedia-pages.rb +78 -58
- data.tar.gz.sig +2 -4
- metadata +15 -15
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0c08643b6ed8f8d1d995683aaa991064cd2257a3f1dec07025f26d0536e281d
|
4
|
+
data.tar.gz: 1e75399e2f80fef5212540d456e7ac905cd91a14de65ed77d6d401d0bc83db2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23195bd7994a9f2cdb40c2eab3373c89e8e20708e4f5ff055fa0def6ff7c93f178ba426aa1374a07cc5ca217e04d0905e9416d0e523611fae2c87ee989a9045a
|
7
|
+
data.tar.gz: 5acb6b674ce42dd2857d4316918c979ab5fab6ce419aee51b0ce15b321cd0c8a9320cb8719104577a4a1f072d5cfb9c9c8cc238e5da8ff068c0adcd2feb1eb5e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/mymedia-pages.rb
CHANGED
@@ -8,40 +8,57 @@ require 'martile'
|
|
8
8
|
require 'kramdown'
|
9
9
|
|
10
10
|
|
11
|
+
module PageReader
|
12
|
+
|
13
|
+
# read the source file
|
14
|
+
#
|
15
|
+
def read(filename)
|
16
|
+
File.read File.join(@media_src, escape(filename))
|
17
|
+
end
|
18
|
+
|
19
|
+
# view the published file
|
20
|
+
#
|
21
|
+
def view(filename)
|
22
|
+
File.read File.join(@home, @public_type, filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
11
27
|
class MyMediaPagesError < Exception
|
12
28
|
end
|
13
29
|
|
14
30
|
class MyMediaPages < MyMedia::Base
|
31
|
+
include MyMedia::IndexReader
|
32
|
+
include PageReader
|
15
33
|
|
16
34
|
def initialize(media_type: media_type='pages',
|
17
35
|
public_type: @public_type=media_type, ext: '.(html|md|txt)',
|
18
|
-
config: nil, log:
|
19
|
-
|
36
|
+
config: nil, log: nil, debug: false)
|
37
|
+
|
20
38
|
super(media_type: media_type, public_type: @public_type=media_type,
|
21
39
|
ext: '.(html|md|txt)', config: config, log: log)
|
22
40
|
|
23
|
-
@media_src = "%s/media/%s" % [@home, media_type]
|
24
41
|
@target_ext = '.html'
|
25
42
|
@static_html = true
|
26
43
|
@debug = debug
|
27
|
-
|
28
|
-
end
|
29
|
-
|
44
|
+
|
45
|
+
end
|
46
|
+
|
30
47
|
def copy_publish(filename, raw_msg='')
|
31
48
|
|
32
49
|
@log.info 'MyMediaPagesinside copy_publish' if @log
|
33
50
|
@filename = filename
|
34
51
|
src_path = File.join(@media_src, filename)
|
35
52
|
|
36
|
-
if File.basename(src_path)[/[a-z]\d{6}T\d{4}\.(?:html)/] then
|
53
|
+
if File.basename(src_path)[/[a-z]\d{6}T\d{4}\.(?:html)/] then
|
37
54
|
return file_publish(src_path, raw_msg)
|
38
55
|
end
|
39
56
|
|
40
57
|
file_publish(src_path, raw_msg) do |destination, raw_destination|
|
41
58
|
|
42
59
|
ext = File.extname(src_path)
|
43
|
-
|
44
|
-
if ext[/\.(?:md|txt)/] then
|
60
|
+
|
61
|
+
if ext[/\.(?:md|txt)/] then
|
45
62
|
|
46
63
|
raw_dest_xml = raw_destination.sub(/html$/,'xml')
|
47
64
|
dest_xml = destination.sub(/html$/,'xml')
|
@@ -49,7 +66,7 @@ class MyMediaPages < MyMedia::Base
|
|
49
66
|
|
50
67
|
|
51
68
|
FileUtils.cp src_path, x_destination
|
52
|
-
|
69
|
+
|
53
70
|
source = x_destination[/\/r\/#{@public_type}.*/]
|
54
71
|
s = @website + source
|
55
72
|
|
@@ -69,8 +86,8 @@ class MyMediaPages < MyMedia::Base
|
|
69
86
|
File.write destination, xsltproc("#{@home}/#{@www}/xsl/#{@public_type}.xsl", dest_xml)
|
70
87
|
|
71
88
|
html_filename = basename(@media_src, src_path).sub(/(?:md|txt)$/,'html')
|
72
|
-
|
73
|
-
|
89
|
+
|
90
|
+
|
74
91
|
xml_filename = html_filename.sub(/html$/,'xml')
|
75
92
|
|
76
93
|
FileUtils.mkdir_p File.dirname(File.join(File.dirname(destination), html_filename))
|
@@ -80,66 +97,68 @@ class MyMediaPages < MyMedia::Base
|
|
80
97
|
FileUtils.cp dest_xml, File.join(File.dirname(dest_xml), xml_filename)
|
81
98
|
|
82
99
|
tags = doc.root.xpath('summary/tags/tag/text()')
|
83
|
-
raw_msg = "%s %s" % [doc.root.text('summary/title'),
|
100
|
+
raw_msg = "%s %s" % [doc.root.text('summary/title'),
|
84
101
|
tags.map {|x| "#%s" % x }.join(' ')]
|
85
|
-
|
86
|
-
|
102
|
+
|
103
|
+
|
87
104
|
@log.info "msg: %s tags: %s" % [raw_msg, tags.inspect]if @log
|
88
105
|
|
89
106
|
|
90
107
|
else
|
91
|
-
|
108
|
+
|
92
109
|
html_filename = basename(@media_src, src_path)
|
93
|
-
|
110
|
+
|
94
111
|
if html_filename =~ /\// then
|
95
112
|
FileUtils.mkdir_p File.dirname(html_filename)
|
96
|
-
end
|
97
|
-
|
113
|
+
end
|
114
|
+
|
98
115
|
FileUtils.cp src_path, destination
|
99
|
-
FileUtils.cp src_path, raw_destination
|
100
|
-
|
116
|
+
FileUtils.cp src_path, raw_destination
|
117
|
+
|
101
118
|
raw_msg = File.read(destination)[/<title>([^<]+)<\/title>/,1]
|
102
119
|
end
|
103
|
-
|
120
|
+
|
104
121
|
if not File.basename(src_path)[/[a-z]\d{6}T\d{4}\.(?:html|md|txt)/] then
|
105
|
-
|
122
|
+
|
106
123
|
@log.info 'MyMediaPages::copy_publish before FileUtils' if @log
|
107
124
|
FileUtils.mkdir_p File.dirname(@home + "/#{@public_type}/" + html_filename)
|
108
125
|
FileUtils.cp destination, @home + "/#{@public_type}/" + html_filename
|
109
126
|
|
110
127
|
if xml_filename then
|
111
|
-
FileUtils.cp dest_xml, @home + "/#{@public_type}/" + xml_filename
|
128
|
+
FileUtils.cp dest_xml, @home + "/#{@public_type}/" + xml_filename
|
112
129
|
end
|
113
130
|
|
114
|
-
static_filepath = @home + "/#{@public_type}/static.xml"
|
115
|
-
x_filename = @static_html == true ? html_filename : xml_filename
|
131
|
+
static_filepath = @home + "/#{@public_type}/static.xml"
|
132
|
+
x_filename = @static_html == true ? html_filename : xml_filename
|
116
133
|
target_url = [@website, @public_type, x_filename].join('/')
|
117
|
-
|
134
|
+
|
118
135
|
if @log then
|
119
136
|
@log.info 'MyMediaPages::copy_publish ->file_publish ' +
|
120
137
|
'before publish_dynarex'
|
121
138
|
end
|
122
|
-
|
123
|
-
publish_dynarex(static_filepath, {title: raw_msg, url: target_url })
|
139
|
+
|
140
|
+
publish_dynarex(static_filepath, {title: raw_msg, url: target_url })
|
124
141
|
|
125
142
|
end
|
126
143
|
|
127
144
|
[raw_msg, target_url]
|
128
|
-
end
|
145
|
+
end
|
129
146
|
|
130
147
|
end
|
131
|
-
|
132
|
-
|
148
|
+
|
149
|
+
|
133
150
|
private
|
134
|
-
|
151
|
+
|
135
152
|
def htmlize(raw_buffer)
|
136
153
|
|
137
154
|
buffer = Martile.new(raw_buffer, ignore_domainlabel: @domain).to_s
|
138
|
-
|
139
155
|
lines = buffer.strip.lines.to_a
|
140
156
|
puts 'lines: ' + lines.inspect if @debug
|
141
157
|
|
142
158
|
raw_title = lines.shift.chomp
|
159
|
+
puts 'lines 2): ' + lines.inspect if @debug
|
160
|
+
|
161
|
+
raise MyMediaPagesError, 'invalid input file' if lines.empty?
|
143
162
|
raw_tags = lines.pop[/[^>]+$/].split
|
144
163
|
|
145
164
|
s = lines.join
|
@@ -147,7 +166,7 @@ class MyMediaPages < MyMedia::Base
|
|
147
166
|
html = Kramdown::Document.new(s).to_html
|
148
167
|
[raw_title, raw_tags, html]
|
149
168
|
|
150
|
-
end
|
169
|
+
end
|
151
170
|
|
152
171
|
def microblog_title(doc)
|
153
172
|
|
@@ -155,7 +174,7 @@ class MyMediaPages < MyMedia::Base
|
|
155
174
|
|
156
175
|
title = summary.text('title')
|
157
176
|
tags = summary.xpath('tags/tag/text()').map{|x| '#' + x}.join(' ')
|
158
|
-
|
177
|
+
|
159
178
|
url = "%s/%s/yy/mm/dd/hhmmhrs.html" % [@website, @media_type]
|
160
179
|
full_title = (url + title + ' ' + tags)
|
161
180
|
|
@@ -166,17 +185,17 @@ class MyMediaPages < MyMedia::Base
|
|
166
185
|
|
167
186
|
title + ' ' + tags
|
168
187
|
|
169
|
-
end
|
170
|
-
|
171
|
-
|
188
|
+
end
|
189
|
+
|
190
|
+
|
172
191
|
def modify_xml(docx, filepath, xslpath='r/')
|
173
192
|
|
174
193
|
if @log then
|
175
194
|
@log.info 'mymedia_pages: inside modify_xml: docx.xml: ' + docx.xml.inspect
|
176
195
|
end
|
177
|
-
|
196
|
+
|
178
197
|
doc = Rexle.new docx.xml pretty: false
|
179
|
-
|
198
|
+
|
180
199
|
if @log then
|
181
200
|
@log.info 'doc.xml: ' + doc.xml.inspect if @log
|
182
201
|
end
|
@@ -189,38 +208,39 @@ class MyMediaPages < MyMedia::Base
|
|
189
208
|
yield(doc) if block_given?
|
190
209
|
File.write filepath, doc.xml(declaration: true, pretty: false)
|
191
210
|
end
|
192
|
-
|
211
|
+
|
193
212
|
def xml(raw_buffer, filename, original_file)
|
194
213
|
|
195
214
|
begin
|
196
215
|
|
197
|
-
|
216
|
+
puts 'before htmlize'
|
198
217
|
raw_title, raw_tags, html = htmlize(raw_buffer)
|
218
|
+
puts 'after htmlize'
|
199
219
|
|
200
|
-
doc = Rexle.new("<body>%s</body>" % html)
|
220
|
+
doc = Rexle.new("<body>%s</body>" % html)
|
201
221
|
|
202
222
|
doc.root.xpath('//a').each do |x|
|
203
223
|
|
204
224
|
next unless x.attributes[:href] and x.attributes[:href].empty?
|
205
|
-
|
225
|
+
|
206
226
|
new_link = x.text.gsub(/\s/,'_')
|
207
227
|
|
208
228
|
x.attributes[:href] = "#{@dynamic_website}/do/#{@public_type}/new/" + new_link
|
209
229
|
x.attributes[:class] = 'new'
|
210
230
|
x.attributes[:title] = x.text + ' (page does not exist)'
|
211
231
|
end
|
212
|
-
|
232
|
+
|
213
233
|
body = doc.root.children.join
|
214
234
|
|
215
|
-
# A special tag can be used to represent a metatag which indicates if
|
216
|
-
# the document access is to be made public. The special tag can either
|
235
|
+
# A special tag can be used to represent a metatag which indicates if
|
236
|
+
# the document access is to be made public. The special tag can either
|
217
237
|
# be a 'p' or 'public'
|
218
238
|
|
219
239
|
access = raw_tags.last[/^(?:p|public)$/] ? raw_tags.pop : nil
|
220
|
-
|
240
|
+
|
221
241
|
xml = RexleBuilder.new
|
222
|
-
|
223
|
-
a = xml.page do
|
242
|
+
|
243
|
+
a = xml.page do
|
224
244
|
xml.summary do
|
225
245
|
xml.title raw_title
|
226
246
|
xml.tags { raw_tags.each {|tag| xml.tag tag }}
|
@@ -231,20 +251,20 @@ class MyMediaPages < MyMedia::Base
|
|
231
251
|
xml.published Time.now.strftime("%d-%m-%Y %H:%M")
|
232
252
|
xml.filetitle original_file[/.*(?=\.\w+$)/]
|
233
253
|
end
|
234
|
-
|
254
|
+
|
235
255
|
xml.body body
|
236
256
|
end
|
237
|
-
|
238
|
-
|
257
|
+
|
258
|
+
|
239
259
|
rescue
|
240
260
|
raise MyMediaPagesError, 'xml(): ' + ($!).inspect
|
241
261
|
end
|
242
262
|
|
243
263
|
return Rexle.new(a)
|
244
|
-
end
|
245
|
-
|
246
|
-
def xsltproc(xslpath, xmlpath)
|
247
|
-
|
264
|
+
end
|
265
|
+
|
266
|
+
def xsltproc(xslpath, xmlpath)
|
267
|
+
|
248
268
|
Nokogiri::XSLT(File.open(xslpath))\
|
249
269
|
.transform(Nokogiri::XML(File.open(xmlpath))).to_xhtml(indent: 0)
|
250
270
|
end
|
data.tar.gz.sig
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mymedia-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,48 +35,48 @@ cert_chain:
|
|
35
35
|
jSG8iFV4kJofCyHyfW6zyZy0d22o23Syxam2rIESaal2RPL7gADDTc8XBe/sFeWr
|
36
36
|
A7Ido2/5qg5YDVloSOHTfzZj
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: mymedia
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0.2'
|
47
44
|
- - ">="
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
46
|
+
version: 0.3.0
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.3'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '0.2'
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.
|
56
|
+
version: 0.3.0
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.3'
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: martile
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 1.
|
66
|
+
version: 1.5.0
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1.
|
69
|
+
version: '1.5'
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.
|
76
|
+
version: 1.5.0
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '1.
|
79
|
+
version: '1.5'
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: kramdown
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: 2.3.1
|
100
100
|
description:
|
101
|
-
email:
|
101
|
+
email: digital.robertson@gmail.com
|
102
102
|
executables: []
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
metadata.gz.sig
CHANGED
Binary file
|