mymedia-blogbase 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mymedia-blogbase.rb +230 -0
- metadata +127 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60220fb57d8d6115444f17d012d841c549ab9aee
|
4
|
+
data.tar.gz: 493dd197c352faf7392447ff3fecccd020a3a514
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 411b82b4582c063de1e8938dc26ebbfc4fe1c90e5633cc52a5d29a855d79d3f4a9b27f88aa47e77af63c509a18b0cdf677bd2e1fdba2251c7c2196913afaf509
|
7
|
+
data.tar.gz: 32cc37fdc9f51c13d259ce0da9c6d20fbbe4b7a7d933ac47a779be5495877343e4ea626184a0de7515349d54a5a17cd42b0ca7028ba0a113cc5b7dfd399fb722
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,230 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: mymedia-blogbase.rb
|
4
|
+
|
5
|
+
require 'rdiscount'
|
6
|
+
require 'mymedia'
|
7
|
+
require 'martile'
|
8
|
+
|
9
|
+
|
10
|
+
class MyMediaBlogBase < MyMedia::Base
|
11
|
+
|
12
|
+
def initialize(media_type: 'blog', public_type: 'blog', ext: 'txt', config: nil)
|
13
|
+
|
14
|
+
super(media_type: media_type, public_type: public_type, ext: ext, config: config)
|
15
|
+
@media_src = "%s/media/%s" % [@home, @public_type]
|
16
|
+
@target_ext = '.html'
|
17
|
+
@rss = true
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def copy_publish(filename, raw_msg='')
|
23
|
+
|
24
|
+
src_path = File.join(@media_src, filename)
|
25
|
+
|
26
|
+
raise "tags missing or too many tags" if File.open(src_path,'r')\
|
27
|
+
.readlines.last.split.length > 5
|
28
|
+
|
29
|
+
file_publish(src_path) do |destination, raw_destination|
|
30
|
+
|
31
|
+
raw_msg = ''
|
32
|
+
|
33
|
+
File.open(destination,'w') do |f|
|
34
|
+
|
35
|
+
txt_destination = destination.sub(/html$/,'txt')
|
36
|
+
FileUtils.cp src_path, txt_destination
|
37
|
+
|
38
|
+
doc = html(File.open(src_path, 'r').read, File.basename(txt_destination))
|
39
|
+
raw_msg = microblog_title(doc)
|
40
|
+
f.write doc.xml
|
41
|
+
end
|
42
|
+
|
43
|
+
FileUtils.cp destination, raw_destination
|
44
|
+
|
45
|
+
raw_msg
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def html(raw_buffer, filename)
|
55
|
+
|
56
|
+
doc = nil
|
57
|
+
|
58
|
+
begin
|
59
|
+
|
60
|
+
buffer = Martile.new(raw_buffer).to_html
|
61
|
+
buffer = string_modifier(buffer)
|
62
|
+
|
63
|
+
a = buffer.strip.lines.to_a
|
64
|
+
a.first.sub!(/^[^#]/, '#\0') # add a '#' to the title of it's not there
|
65
|
+
# make a list from the tags
|
66
|
+
|
67
|
+
s = a.pop[/[^>]+$/].split.map{|x| "<li>%s</li>" % x}.join
|
68
|
+
a.push "%s<ul>%s</ul>" % [$`, s]
|
69
|
+
|
70
|
+
s = a.join.gsub(/(?:^\[|\s\[)[^\]]+\]\((https?:\/\/[^\s]+)/) do |x|
|
71
|
+
next x if x[/#{@domain}/]
|
72
|
+
s2 = x[/https?:\/\/([^\/]+)/,1].split(/\./)
|
73
|
+
r = s2.length >= 3 ? s2[1..-1] : s2
|
74
|
+
"%s [%s]" % [x, r.join('.')]
|
75
|
+
end
|
76
|
+
|
77
|
+
raw_body = "<body>%s</body>" % RDiscount.new(s).to_html
|
78
|
+
|
79
|
+
body = Rexle.new(raw_body)
|
80
|
+
|
81
|
+
#format the code in the body
|
82
|
+
|
83
|
+
document_modifier(body)
|
84
|
+
|
85
|
+
ul = body.root.xpath('ul').last
|
86
|
+
tags = ul.deep_clone
|
87
|
+
|
88
|
+
ul.delete
|
89
|
+
dl = "<dl id='info'><dt>Tags:</dt><dd/>\
|
90
|
+
<dt>Source:</dt><dd><a href='#{filename}'>#{File.basename(filename)}</a></dd>\
|
91
|
+
<dt>Published:</dt><dd>#{Time.now.strftime("%d-%m-%Y %H:%M")}</dd></dl>"
|
92
|
+
|
93
|
+
body.root.add Rexle.new(dl)
|
94
|
+
body.root.element('dl/dd').add tags
|
95
|
+
|
96
|
+
title = "%s %s | %s" % [body.root.text('h1'), \
|
97
|
+
tags.xpath('li/text()').map{|x| "[%s]" % x}.join(' '), @domain]
|
98
|
+
|
99
|
+
|
100
|
+
xml = RexleBuilder.new
|
101
|
+
|
102
|
+
a = xml.html do
|
103
|
+
xml.head do
|
104
|
+
xml.title title
|
105
|
+
xml.link({rel: 'stylesheet', type: 'text/css', \
|
106
|
+
href: @website + '/blog/layout.css', media: 'screen, projection, tv, print'},'')
|
107
|
+
xml.link({rel: 'stylesheet', type: 'text/css', \
|
108
|
+
href: @website + '/blog/style.css', media: 'screen, projection, tv, print'},'')
|
109
|
+
add_css_js(xml)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
doc = Rexle.new(a)
|
114
|
+
doc.root.add body
|
115
|
+
|
116
|
+
rescue
|
117
|
+
@logger.debug "mymedia-blogbase.rb: html: " + ($!).to_s
|
118
|
+
end
|
119
|
+
|
120
|
+
return doc
|
121
|
+
end
|
122
|
+
|
123
|
+
def xml(raw_buffer, filename, original_file)
|
124
|
+
|
125
|
+
begin
|
126
|
+
|
127
|
+
buffer = Martile.new(raw_buffer).to_html
|
128
|
+
|
129
|
+
lines = buffer.strip.lines.to_a
|
130
|
+
raw_title = lines.shift.chomp
|
131
|
+
raw_tags = lines.pop[/[^>]+$/].split
|
132
|
+
|
133
|
+
s = lines.join.gsub(/(?:^\[|\s\[)[^\]]+\]\((https?:\/\/[^\s]+)/) do |x|
|
134
|
+
|
135
|
+
next x if x[/#{@domain}/]
|
136
|
+
s2 = x[/https?:\/\/([^\/]+)/,1].split(/\./)
|
137
|
+
r = s2.length >= 3 ? s2[1..-1] : s2
|
138
|
+
"%s [%s]" % [x, r.join('.')]
|
139
|
+
end
|
140
|
+
|
141
|
+
html = RDiscount.new(s).to_html
|
142
|
+
doc = Rexle.new("<body>%s</body>" % html)
|
143
|
+
|
144
|
+
doc.root.xpath('//a').each do |x|
|
145
|
+
|
146
|
+
next unless x.attributes[:href].empty?
|
147
|
+
|
148
|
+
new_link = x.text.gsub(/\s/,'_')
|
149
|
+
|
150
|
+
x.attributes[:href] = "#{@dynamic_website}/do/#{@public_type}/new/" + new_link
|
151
|
+
x.attributes[:class] = 'new'
|
152
|
+
x.attributes[:title] = x.text + ' (page does not exist)'
|
153
|
+
end
|
154
|
+
|
155
|
+
body = doc.root.children.join
|
156
|
+
|
157
|
+
|
158
|
+
xml = RexleBuilder.new
|
159
|
+
|
160
|
+
a = xml.page do
|
161
|
+
xml.summary do
|
162
|
+
xml.title raw_title
|
163
|
+
xml.tags { raw_tags.each {|tag| xml.tag tag }}
|
164
|
+
xml.source_url filename
|
165
|
+
xml.source_file File.basename(filename)
|
166
|
+
xml.original_file original_file
|
167
|
+
xml.published Time.now.strftime("%d-%m-%Y %H:%M")
|
168
|
+
end
|
169
|
+
|
170
|
+
xml.body body
|
171
|
+
end
|
172
|
+
|
173
|
+
rescue
|
174
|
+
@logger.debug "mymedia-blogbase.rb: html: " + ($!).to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
return Rexle.new(a)
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def microblog_title2(doc)
|
182
|
+
|
183
|
+
summary = doc.root.element('summary')
|
184
|
+
title = summary.text('title')
|
185
|
+
tags = summary.xpath('tags/tag/text()').map{|x| '#' + x}.join ' '
|
186
|
+
|
187
|
+
url = "%s/%s/yy/mm/dd/hhmmhrs.html" % [@website, @media_type]
|
188
|
+
full_title = (url + title + ' ' + tags)
|
189
|
+
|
190
|
+
if full_title.length > 140 then
|
191
|
+
extra = full_title.length - 140
|
192
|
+
title = title[0..-(extra)] + ' ...'
|
193
|
+
end
|
194
|
+
|
195
|
+
title + ' ' + tags
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
def microblog_title(doc)
|
200
|
+
|
201
|
+
a = doc.root.element('head/title').text.split(/(?=\[(\w+)\])/)
|
202
|
+
tags = a[1..-1].select.with_index {|x, i| i % 2 == 0}.map{|x| '#' + x}.join ' '
|
203
|
+
title = a[0]
|
204
|
+
url = "%s/%s/yy/mm/dd/hhmmhrs.html" % [@website, @media_type]
|
205
|
+
full_title = (url + title + ' ' + tags)
|
206
|
+
|
207
|
+
if full_title.length > 140 then
|
208
|
+
extra = full_title.length - 140
|
209
|
+
title = title[0..-(extra)] + ' ...'
|
210
|
+
end
|
211
|
+
|
212
|
+
title + ' ' + tags
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
def add_css_js(xml)
|
219
|
+
# overridden in the RSF file
|
220
|
+
end
|
221
|
+
def string_modifier(s)
|
222
|
+
# overridden in the RSF file
|
223
|
+
s
|
224
|
+
end
|
225
|
+
def document_modifier(body)
|
226
|
+
# overridden in the RSF file
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mymedia-blogbase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDA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0g225XWyDZ8073F5s78EsCfH8+lBgtZKQV6kXXJF
|
29
|
+
hq/l8xdNz6l8fQfc3utRZg4urX6tcV4BDW+A1vVkqseyX8HnHNNKDsQ2MvAhQ4Os
|
30
|
+
o9HkfVkjI2Y1VVSz/n/tjf87jChWBkEaPNlAgZURNHTsNW2bp7wmaigFNERpAPwA
|
31
|
+
W6oyq4p6WDOpJ2y9HFHWdg8TmF1bZj7k6y+5Tx6uce9VL6Jj3b8fa1YfHrqAU/4Z
|
32
|
+
ZwDOWqyDyRdF8g==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2014-10-11 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdiscount
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.1'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.1.7.1
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.1'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.1.7.1
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mymedia
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.1.0
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.1'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.0
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: martile
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.3'
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.3.5
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0.3'
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.3.5
|
96
|
+
description:
|
97
|
+
email: james@r0bertson.co.uk
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- lib/mymedia-blogbase.rb
|
103
|
+
homepage: https://github.com/jrobertson/mymedia-blogbase
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Provides the basic features to publish page content
|
127
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|