mymedia-pages 0.2.0 → 0.4.0

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