mymedia-pages 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 14a2a8b0474a640a34ec3ae0426109392d9c6bdf
4
- data.tar.gz: 92db4444d3d0d76502e7b25c2e8aff15d4a0fc9a
3
+ metadata.gz: a11ed7245662312bd00c2819dcbfdca0d9f7b988
4
+ data.tar.gz: 67d1a34083a0940f4724df2888cdde16c8e60d3a
5
5
  SHA512:
6
- metadata.gz: 4333ae99ebfed5ff4a4b81d2be64ed08d7bd38a4cd517caa0a3aab3788ce9e8549871acec8ba2a1a090742e11fdede85e8d6b28e46f9feb07681642750a6c235
7
- data.tar.gz: 7c47461160d52875fe4778ad2d45f918f67ab514e3e5bec7cf820193ce94e555b533c42a7065aa357ac923608fcf7ce91d22df99ac4e1772bd12e20e1b0625be
6
+ metadata.gz: 2523bd19e79fd919921f51c30ee5739b327baa313d73157d10ae777435847980c28493e9c6647e91ccf174481a84b41be79ea4565572fa9b82c7717f8af34c0f
7
+ data.tar.gz: a99dadae12940d2e4c4bb41716666590230727644c5098a0ea67281e7e893ced5fce84ca55f16fb9f1b2416acaa8ff457769f92e287643ba3e47f3ebbfec478e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/mymedia-pages.rb CHANGED
@@ -6,17 +6,15 @@
6
6
  require 'mymedia-blogbase'
7
7
 
8
8
 
9
- class MyMediaPages < MyMediaBlogBase
9
+ class MyMediaPages < MyMedia::Base
10
10
 
11
11
  def initialize(config: nil)
12
12
 
13
- super(media_type: 'pages', public_type: @public_type='pages', ext: '.(html|md)', config: config)
13
+ super(media_type: 'pages', public_type: @public_type='pages', ext: '.(html|md|txt)', config: config)
14
14
  @media_src = "%s/media/pages" % @home
15
- end
16
-
17
- def copy_publish_to_be_removed(src_path, raw_msg='')
18
- msg = super(src_path, raw_msg)
19
- end
15
+ @target_ext = '.html'
16
+
17
+ end
20
18
 
21
19
  def copy_publish(filename, raw_msg='')
22
20
 
@@ -32,18 +30,19 @@ class MyMediaPages < MyMediaBlogBase
32
30
  #FileUtils.cp src_path, destination
33
31
  #FileUtils.cp src_path, raw_destination
34
32
 
35
- if File.extname(src_path) == '.md' then
36
-
33
+ ext = File.extname(src_path)
34
+
35
+ if ext[/\.(?:md|txt)/] then
36
+
37
37
  raw_dest_xml = raw_destination.sub(/html$/,'xml')
38
- md_destination = raw_destination.sub(/html$/,'md')
39
- FileUtils.cp src_path, md_destination
38
+ x_destination = raw_destination.sub(/html$/,ext)
39
+ FileUtils.cp src_path, x_destination
40
40
 
41
- source = md_destination[/\/r\/#{@public_type}.*/]
41
+ source = x_destination[/\/r\/#{@public_type}.*/]
42
42
  s = @website + source
43
- absolute_path = s[/https?:\/\/[^\/]+([^$]+)/,1]
43
+ relative_path = s[/https?:\/\/[^\/]+([^$]+)/,1]
44
44
 
45
- doc = xml(File.open(src_path, 'r').read,
46
- absolute_path, filename)
45
+ doc = xml(File.open(src_path, 'r').read, relative_path, filename)
47
46
 
48
47
  modify_xml(doc, raw_dest_xml)
49
48
 
@@ -57,19 +56,23 @@ class MyMediaPages < MyMediaBlogBase
57
56
 
58
57
  File.write destination,
59
58
  Nokogiri::XSLT(xsl).transform(Nokogiri::XML(File.read raw_dest_xml))
60
- else
61
- FileUtils.cp src_path, destination
62
- FileUtils.cp src_path, raw_destination
59
+
60
+ else
61
+ FileUtils.cp src_path, destination
62
+ FileUtils.cp src_path, raw_destination
63
63
  end
64
-
65
64
 
66
- if not File.basename(src_path)[/[pw]\d{6}T\d{4}\.(?:html|md)/] then
67
- html_filename = File.basename(src_path).sub(/md$/,'html')
65
+ if not File.basename(src_path)[/[pw]\d{6}T\d{4}\.(?:html|md|txt)/] then
66
+
67
+ html_filename = File.basename(src_path).sub(/(?:md|txt)$/,'html')
68
68
 
69
69
  FileUtils.cp destination, @home + "/#{@public_type}/" + html_filename
70
+
70
71
  html_filepath = @home + "/#{@public_type}/static.xml"
71
72
  target_url = [@website, @public_type, html_filename].join('/')
73
+
72
74
  publish_dynarex(html_filepath, {title: html_filename, url: target_url })
75
+
73
76
  tags = doc.root.xpath('summary/tags/tag/text()')
74
77
 
75
78
  raw_msg = "%s %s" % [doc.root.text('summary/title'),
@@ -82,15 +85,100 @@ class MyMediaPages < MyMediaBlogBase
82
85
 
83
86
  end
84
87
 
88
+
85
89
  private
86
90
 
91
+ def htmlize(raw_buffer)
92
+
93
+ buffer = Martile.new(raw_buffer).to_html
94
+
95
+ lines = buffer.strip.lines.to_a
96
+ raw_title = lines.shift.chomp
97
+ raw_tags = lines.pop[/[^>]+$/].split
98
+
99
+ s = lines.join.gsub(/(?:^\[|\s\[)[^\]]+\]\((https?:\/\/[^\s]+)/) do |x|
100
+
101
+ next x if x[/#{@domain}/]
102
+ s2 = x[/https?:\/\/([^\/]+)/,1].split(/\./)
103
+ r = s2.length >= 3 ? s2[1..-1] : s2
104
+ "%s [%s]" % [x, r.join('.')]
105
+ end
106
+
107
+ html = RDiscount.new(s).to_html
108
+ [raw_title, raw_tags, html]
109
+
110
+ end
111
+
112
+ def microblog_title(doc)
113
+
114
+ summary = doc.root.element('summary')
115
+ title = summary.text('title')
116
+ tags = summary.xpath('tags/tag/text()').map{|x| '#' + x}.join ' '
117
+
118
+ url = "%s/%s/yy/mm/dd/hhmmhrs.html" % [@website, @media_type]
119
+ full_title = (url + title + ' ' + tags)
120
+
121
+ if full_title.length > 140 then
122
+ extra = full_title.length - 140
123
+ title = title[0..-(extra)] + ' ...'
124
+ end
125
+
126
+ title + ' ' + tags
127
+
128
+ end
129
+
130
+
87
131
  def modify_xml(doc, filepath)
88
132
 
89
- raw_msg = microblog_title2(doc)
133
+ raw_msg = microblog_title(doc)
90
134
  doc.instructions.push %w(xml-stylesheet title='XSL_formatting' type='text/xsl') + ["href='#{@website}/r/xsl/#{@public_type}.xsl'"]
91
135
  doc = yield(doc) if block_given?
92
136
  File.write filepath, doc.xml(pretty: true)
93
137
  end
94
-
138
+
139
+ def xml(raw_buffer, filename, original_file)
140
+
141
+ begin
142
+
143
+ raw_title, raw_tags, html = htmlize(raw_buffer)
144
+
145
+ doc = Rexle.new("<body>%s</body>" % html)
146
+
147
+ doc.root.xpath('//a').each do |x|
148
+
149
+ next unless x.attributes[:href].empty?
150
+
151
+ new_link = x.text.gsub(/\s/,'_')
152
+
153
+ x.attributes[:href] = "#{@dynamic_website}/do/#{@public_type}/new/" + new_link
154
+ x.attributes[:class] = 'new'
155
+ x.attributes[:title] = x.text + ' (page does not exist)'
156
+ end
157
+
158
+ body = doc.root.children.join
159
+
160
+
161
+ xml = RexleBuilder.new
162
+
163
+ a = xml.page do
164
+ xml.summary do
165
+ xml.title raw_title
166
+ xml.tags { raw_tags.each {|tag| xml.tag tag }}
167
+ xml.source_url filename
168
+ xml.source_file File.basename(filename)
169
+ xml.original_file original_file
170
+ xml.published Time.now.strftime("%d-%m-%Y %H:%M")
171
+ end
172
+
173
+ xml.body body
174
+ end
175
+
176
+ rescue
177
+ @logger.debug "mymedia-blogbase.rb: html: " + ($!).to_s
178
+ end
179
+
180
+ return Rexle.new(a)
181
+ end
182
+
95
183
 
96
184
  end
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  R8qQYTqUH5uyN1gXTamDXNnXrSWNIRgATqBFU0Rk4ia1O2X6/oMnJctbKR+A3n78
32
32
  zZLvJwXE0u524g==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-10-11 00:00:00.000000000 Z
34
+ date: 2014-10-12 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mymedia-blogbase
metadata.gz.sig CHANGED
Binary file