tdiary-contrib 5.1.2 → 5.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/js/gyazo.js +23 -0
- data/lib/tdiary/contrib/version.rb +1 -1
- data/plugin/gyazo.rb +90 -0
- data/plugin/image_ex.rb +1 -1
- data/plugin/ja/openbd.rb +40 -0
- data/plugin/openbd.rb +306 -0
- data/plugin/puboo.rb +10 -10
- data/plugin/twitter.rb +5 -41
- data/plugin/twitter_js.rb +8 -57
- data/spec/spec_helper.rb +1 -1
- metadata +35 -5
- data/spec/twitter_js_spec.rb +0 -116
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e197ac500c058bedf4550b8348befa06bf061335dd95e70aebed756de26ce461
|
4
|
+
data.tar.gz: 32eb86bd9e7c014e1dc1b0a5fd046810cf494c26ed508a2708e70d00eff42917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08910590a8a4409a832c67f9e2105fc39f25a2b9515fcc86a247990267d3ccd5410d181ae23e68b68362a66b91d2bd1c4cc3ffeaebd90cf8c55c6837ff74b25d'
|
7
|
+
data.tar.gz: ff83cf724de444e5f1c61518d2be03457eb1cf65aa3c9ff7fd58109a763f902bb6180abc7c3a7fad78c8524c68e44e9751406fa14e5c424701cd6c88c50882bf
|
data/js/gyazo.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* gyazo.js: gyazo plugin for tDiary
|
3
|
+
*
|
4
|
+
* SPDX-License-Identifier: GPL-2.0-or-later
|
5
|
+
*/
|
6
|
+
$(function() {
|
7
|
+
$('.gyazo-images img')
|
8
|
+
.on({
|
9
|
+
'mouseenter': function(){
|
10
|
+
$(this).css('cursor', 'pointer');
|
11
|
+
},
|
12
|
+
'mouseleave': function(){
|
13
|
+
$(this).css('cursor', 'default');
|
14
|
+
},
|
15
|
+
'click': function(){
|
16
|
+
var url = $(this).attr('data-url');
|
17
|
+
var text = $.makePluginTag('gyazo', function(){
|
18
|
+
return ["'" + url + "'", "'[description]'"]
|
19
|
+
})
|
20
|
+
$('#body').insertAtCaret(text);
|
21
|
+
}
|
22
|
+
})
|
23
|
+
})
|
data/plugin/gyazo.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# gyazo.rb: gyazo plugin for tDiary
|
3
|
+
#
|
4
|
+
# SPDX-License-Identifier: GPL-2.0-or-later
|
5
|
+
#
|
6
|
+
require 'net/http'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
if /^(form|edit|formplugin|showcomment)$/ =~ @mode then
|
10
|
+
enable_js('gyazo.js')
|
11
|
+
end
|
12
|
+
|
13
|
+
def gyazo(permalink_url, alt = '[description]', style = 'photo')
|
14
|
+
size = @conf['gyazo_max_size'] || 512
|
15
|
+
begin
|
16
|
+
oembed = JSON.parse(Net::HTTP.get(URI("https://api.gyazo.com/api/oembed?url=#{permalink_url}")), symbolize_names: true)
|
17
|
+
rescue => e
|
18
|
+
@logger.error(e)
|
19
|
+
return ''
|
20
|
+
end
|
21
|
+
url = oembed[:url].gsub(%r|/thumb/\d+/|, "/thumb/#{size}/")
|
22
|
+
width = oembed[:width].to_i
|
23
|
+
height = oembed[:height].to_i
|
24
|
+
if width > 0 && height > 0
|
25
|
+
if width > height
|
26
|
+
height = size * height / width
|
27
|
+
width = size
|
28
|
+
else
|
29
|
+
width = size * width / height
|
30
|
+
height = size
|
31
|
+
end
|
32
|
+
%Q[<img src="#{url}" class="#{style}" width=#{width} height=#{height} alt="#{alt}" title="#{alt}">]
|
33
|
+
else # no size informations in API
|
34
|
+
%Q[<img src="#{url}" class="#{style}" width=#{size} alt="#{alt}" title="#{alt}">]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def gyazo_right(permalink_url, alt = '[description]')
|
39
|
+
gyazo(permalink_url, alt, 'right')
|
40
|
+
end
|
41
|
+
|
42
|
+
def gyazo_left(permalink_url, alt = '[description]')
|
43
|
+
gyazo(permalink_url, alt, 'left')
|
44
|
+
end
|
45
|
+
|
46
|
+
def gyazo_list
|
47
|
+
endpoint = "https://api.gyazo.com/api/images"
|
48
|
+
access_token = @conf['gyazo_token']
|
49
|
+
return [] if access_token == nil || access_token.empty?
|
50
|
+
per_page = @conf['gyazo_max_images'] || 5
|
51
|
+
uri = "#{endpoint}?access_token=#{access_token};per_page=#{per_page}"
|
52
|
+
begin
|
53
|
+
JSON.parse(Net::HTTP.get(URI(uri)), symbolize_names: true).map{|i|
|
54
|
+
[i[:permalink_url], i[:thumb_url]]
|
55
|
+
}.delete_if{|is|
|
56
|
+
is[1].empty?
|
57
|
+
}
|
58
|
+
rescue => e
|
59
|
+
@logger.error(e)
|
60
|
+
return []
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
add_form_proc() do |date|
|
65
|
+
'<div class="form"><div class="caption">Gyazo</div><div class="gyazo-images">' +
|
66
|
+
gyazo_list.map{|i|
|
67
|
+
%Q[<img src="#{i[1]}" data-url="#{i[0]}"> ]
|
68
|
+
}.join +
|
69
|
+
'</div></div>'
|
70
|
+
end
|
71
|
+
|
72
|
+
add_conf_proc('gyazo', 'Gyazo') do
|
73
|
+
if @mode == 'saveconf'
|
74
|
+
@conf['gyazo_token'] = @cgi.params['gyazo_token'][0]
|
75
|
+
@conf['gyazo_max_images'] = @cgi.params['gyazo_max_images'][0].to_i
|
76
|
+
@conf['gyazo_max_size'] = @cgi.params['gyazo_max_size'][0].to_i
|
77
|
+
end
|
78
|
+
@conf['gyazo_max_images'] = 5 if @conf['gyazo_max_images'].to_i < 1
|
79
|
+
@conf['gyazo_max_size'] = 512 if @conf['gyazo_max_size'].to_i < 1
|
80
|
+
|
81
|
+
r = ''
|
82
|
+
r << %Q|<h3 class="subtitle">Gyazo API Access Token</h3>|
|
83
|
+
r << %Q|<p>Get your token from <a href="https://gyazo.com/oauth/applications">Gyazo Applications</a></p>|
|
84
|
+
r << %Q|<p><input name="gyazo_token" value="#{h @conf['gyazo_token']}" size=64></p>|
|
85
|
+
r << %Q|<h3 class="subtitle">Max images in list</h3>|
|
86
|
+
r << %Q|<p><input name="gyazo_token" value="#{h @conf['gyazo_max_images']}" size=3></p>|
|
87
|
+
r << %Q|<h3 class="subtitle">Max image size</h3>|
|
88
|
+
r << %Q|<p><input name="gyazo_token" value="#{h @conf['gyazo_max_size']}" size=4> px</p>|
|
89
|
+
r
|
90
|
+
end
|
data/plugin/image_ex.rb
CHANGED
@@ -374,7 +374,7 @@ add_form_proc do |date|
|
|
374
374
|
posttable << %Q[</TR></TABLE>]
|
375
375
|
end
|
376
376
|
|
377
|
-
if @conf.respond_to?(:style) and @conf.style =~ /Wiki$/i
|
377
|
+
if @conf.respond_to?(:style) and @conf.style =~ /(Wiki|GFM)$/i
|
378
378
|
image_plugin_tag1 = "{{"
|
379
379
|
image_plugin_tag2 = "}}"
|
380
380
|
elsif @conf.respond_to?(:style) and @conf.style =~ /RD$/i
|
data/plugin/ja/openbd.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Japanese resource of openBD plugin
|
3
|
+
#
|
4
|
+
# Copyright (C) 2020 OGAWA KenIchi <kenichi@ice.email.ne.jp>
|
5
|
+
# You can redistribute it and/or modify it under GPL2 or any later version.
|
6
|
+
#
|
7
|
+
|
8
|
+
@openbd_label_title = 'isbn_imageプラグインで商品名を'
|
9
|
+
@openbd_label_title_hide = '表示しない'
|
10
|
+
@openbd_label_title_show = '表示する'
|
11
|
+
@openbd_label_clearcache = 'キャッシュの削除'
|
12
|
+
@openbd_label_clearcache_desc = '書籍情報のキャッシュを削除する'
|
13
|
+
|
14
|
+
@openbd_label_default_image = 'デフォルトの画像ファイル'
|
15
|
+
@openbd_label_default_image_desc =
|
16
|
+
'書影がない場合に表示する画像ファイルのパスを指定します。' \
|
17
|
+
'未指定の場合はデフォルトの画像が表示されます。'
|
18
|
+
|
19
|
+
@openbd_label_image_width = '書影の表示幅'
|
20
|
+
@openbd_label_image_width_desc =
|
21
|
+
'数値を指定すると書影を表すimg要素のwidth属性に値が出力されます。'
|
22
|
+
|
23
|
+
@openbd_label_image_height = '書影の表示高'
|
24
|
+
@openbd_label_image_height_desc =
|
25
|
+
'数値を指定すると書影を表すimg要素のheight属性に値が出力されます。'
|
26
|
+
|
27
|
+
@openbd_label_detail_image_width = 'isbn_detail使用時の書影の表示幅'
|
28
|
+
@openbd_label_detail_image_width_desc =
|
29
|
+
'数値を指定すると書影を表すimg要素のwidth属性に値が出力されます。'
|
30
|
+
|
31
|
+
@openbd_label_detail_image_height = 'isbn_detail使用時の書影の表示高'
|
32
|
+
@openbd_label_detail_image_height_desc =
|
33
|
+
'数値を指定すると書影を表すimg要素のheight属性に値が出力されます。'
|
34
|
+
|
35
|
+
# Local Variables:
|
36
|
+
# mode: ruby
|
37
|
+
# indent-tabs-mode: t
|
38
|
+
# tab-width: 3
|
39
|
+
# ruby-indent-level: 3
|
40
|
+
# End:
|
data/plugin/openbd.rb
ADDED
@@ -0,0 +1,306 @@
|
|
1
|
+
# openbd.rb
|
2
|
+
#
|
3
|
+
# Copyright (C) 2020 OGAWA KenIchi <kenichi@ice.email.ne.jp>
|
4
|
+
# You can redistribute it and/or modify it under GPL2 or any later version.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "net/http"
|
8
|
+
require "json"
|
9
|
+
require "uri"
|
10
|
+
|
11
|
+
module OpenBD
|
12
|
+
class Item
|
13
|
+
attr_reader :isbn
|
14
|
+
|
15
|
+
def initialize(isbn, json)
|
16
|
+
@isbn = isbn
|
17
|
+
@data = JSON.parse(json)[0] || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def normalized_isbn
|
21
|
+
nil_if_empty(@data.dig("summary", "isbn"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_url
|
25
|
+
nil_if_empty(@data.dig("summary", "cover"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def title
|
29
|
+
nil_if_empty(@data.dig("summary", "title"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def author
|
33
|
+
nil_if_empty(@data.dig("summary", "author"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def title_and_author
|
37
|
+
author ? "#{title}(#{author})" : title
|
38
|
+
end
|
39
|
+
|
40
|
+
def publisher
|
41
|
+
nil_if_empty(@data.dig("summary", "publisher"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def price
|
45
|
+
price = @data.dig("onix", "ProductSupply", "SupplyDetail", "Price", 0)
|
46
|
+
return nil unless price
|
47
|
+
value = price["PriceAmount"]
|
48
|
+
currency_code = price["CurrencyCode"]
|
49
|
+
case currency_code
|
50
|
+
when "JPY"
|
51
|
+
"#{value}円"
|
52
|
+
else
|
53
|
+
"#{currency_code} #{value}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private def nil_if_empty(s)
|
58
|
+
s&.empty? ? nil : s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Cache
|
63
|
+
def initialize(cache_path)
|
64
|
+
@dir = File.join(cache_path, "openbd")
|
65
|
+
end
|
66
|
+
|
67
|
+
def load(isbn)
|
68
|
+
File.read(path_for(isbn))
|
69
|
+
rescue Errno::ENOENT
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def save(isbn, json)
|
74
|
+
Dir.mkdir(@dir) unless File.directory?(@dir)
|
75
|
+
File.write(path_for(isbn), json)
|
76
|
+
end
|
77
|
+
|
78
|
+
def clear
|
79
|
+
Dir.glob("#{@dir}/*").each { |f| File.delete(f) }
|
80
|
+
end
|
81
|
+
|
82
|
+
private def path_for(isbn)
|
83
|
+
File.join(@dir, "#{isbn}.json")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module_function
|
88
|
+
|
89
|
+
def get_item(isbn, cache_path, mode)
|
90
|
+
cache = OpenBD::Cache.new(cache_path)
|
91
|
+
json = cache.load(isbn) if mode != "preview"
|
92
|
+
unless json
|
93
|
+
uri = URI("https://api.openbd.jp/v1/get?isbn=#{isbn}")
|
94
|
+
response = Net::HTTP.get_response(uri)
|
95
|
+
response.value # raise on errors
|
96
|
+
json = response.body
|
97
|
+
cache.save(isbn, json)
|
98
|
+
end
|
99
|
+
OpenBD::Item.new(isbn, json)
|
100
|
+
end
|
101
|
+
|
102
|
+
def reference_url(item)
|
103
|
+
isbn13 = item.normalized_isbn
|
104
|
+
if isbn13
|
105
|
+
"https://www.hanmoto.com/bd/isbn/#{isbn13}"
|
106
|
+
else
|
107
|
+
isbn = item.isbn.length == 13 ? isbn13to10(item.isbn) : item.isbn
|
108
|
+
"https://www.amazon.co.jp/dp/#{isbn}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def image_info(item, conf)
|
113
|
+
width = conf["openbd.image_width"]
|
114
|
+
height = conf["openbd.image_height"]
|
115
|
+
url = item.image_url || conf["openbd.default_image"]
|
116
|
+
if !url || url.empty?
|
117
|
+
url = <<~EOS
|
118
|
+
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAECAIAAADETxJQAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
|
119
|
+
jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAXSURBVBhXYzx8+DADGDBBKCDAZDEwAABXngJR
|
120
|
+
1c/tyAAAAABJRU5ErkJggg==
|
121
|
+
EOS
|
122
|
+
url.rstrip!
|
123
|
+
width = 200 if !width && !height
|
124
|
+
end
|
125
|
+
{ url: url, width: width, height: height }
|
126
|
+
end
|
127
|
+
|
128
|
+
# from tdiary-core/lib/aws/pa_api.rb
|
129
|
+
def isbn13to10(isbn13)
|
130
|
+
sum, = isbn13[3, 9].split(//).map(&:to_i).reduce([0,10]){|s,d|[s[0] + d * s[1], s[1]-1]}
|
131
|
+
return isbn13[3, 9] + %w(0 1 2 3 4 5 6 7 8 9 X 0)[11 - sum % 11]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def openbd_image(item, label, css_class)
|
136
|
+
label ||= item.title_and_author || item.isbn
|
137
|
+
href = OpenBD.reference_url(item)
|
138
|
+
if @mode == "categoryview"
|
139
|
+
img = ""
|
140
|
+
else
|
141
|
+
alt = ""
|
142
|
+
if @conf["amazon.hidename"] || css_class != "amazon"
|
143
|
+
label, alt = alt, label
|
144
|
+
end
|
145
|
+
image = OpenBD.image_info(item, @conf)
|
146
|
+
width = image[:width]
|
147
|
+
height = image[:height]
|
148
|
+
img_width = width && %Q|width="#{h width}"|
|
149
|
+
img_height = height && %Q|height="#{h height}"|
|
150
|
+
img = <<~EOS
|
151
|
+
<img class="#{h css_class}"
|
152
|
+
src="#{h image[:url]}" #{img_width} #{img_height}
|
153
|
+
alt="#{h alt}">
|
154
|
+
EOS
|
155
|
+
end
|
156
|
+
%Q|<a href="#{h href}">#{img.rstrip}#{h label}</a>|
|
157
|
+
end
|
158
|
+
|
159
|
+
def openbd_process(isbn, &block)
|
160
|
+
isbn = isbn.to_s.strip.gsub("-", "")
|
161
|
+
block.call(OpenBD.get_item(isbn, @cache_path, @mode))
|
162
|
+
rescue => e
|
163
|
+
@logger.error "openbd.rb: isbn=#{isbn}, message=#{e.message}"
|
164
|
+
message = "[openBD plugin error]"
|
165
|
+
if @mode == "preview"
|
166
|
+
message << %Q|<span class="message">(#{h e.message})</span>|
|
167
|
+
end
|
168
|
+
message
|
169
|
+
end
|
170
|
+
|
171
|
+
def isbn_image(isbn, label = nil )
|
172
|
+
openbd_process(isbn) do |item|
|
173
|
+
openbd_image(item, label, "amazon")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def isbn_image_left(isbn, label = nil)
|
178
|
+
openbd_process(isbn) do |item|
|
179
|
+
openbd_image(item, label, "left")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def isbn_image_right(isbn, label = nil)
|
184
|
+
openbd_process(isbn) do |item|
|
185
|
+
openbd_image(item, label, "right")
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def isbn(isbn, label = nil)
|
190
|
+
openbd_process(isbn) do |item|
|
191
|
+
label ||= item.title_and_author || item.isbn
|
192
|
+
%Q|<a href="#{h OpenBD.reference_url(item)}">#{h label}</a>|
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def isbn_detail(isbn)
|
197
|
+
openbd_process(isbn) do |item|
|
198
|
+
image = OpenBD.image_info(item, @conf)
|
199
|
+
width = @conf["openbd.detail_image_width"]
|
200
|
+
height = @conf["openbd.detail_image_height"]
|
201
|
+
width = 57 if !width && !height
|
202
|
+
img_width = width && %Q|width="#{h width}"|
|
203
|
+
img_height = height && %Q|height="#{h height}"|
|
204
|
+
url = OpenBD.reference_url(item)
|
205
|
+
<<-EOS
|
206
|
+
<a class="amazon-detail" href="#{h url}"><span class="amazon-detail">
|
207
|
+
<img class="amazon-detail left"
|
208
|
+
src="#{h image[:url]}" #{img_width} #{img_height} alt="">
|
209
|
+
<span class="amazon-detail-desc">
|
210
|
+
<span class="amazon-title">#{h item.title}</span><br>
|
211
|
+
<span class="amazon-author">#{h item.author || "-"}</span><br>
|
212
|
+
<span class="amazon-label">#{h item.publisher || "-"}</span><br>
|
213
|
+
<span class="amazon-price">#{h item.price || "-"}</span>
|
214
|
+
</span>
|
215
|
+
</span></a>
|
216
|
+
EOS
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# for compatibility
|
221
|
+
alias isbnImgLeft isbn_image_left
|
222
|
+
alias isbnImgRight isbn_image_right
|
223
|
+
alias isbnImg isbn_image
|
224
|
+
alias amazon isbn_image
|
225
|
+
|
226
|
+
add_conf_proc("openbd", "openBD") do
|
227
|
+
if @mode == "saveconf" then
|
228
|
+
@conf["amazon.hidename"] = (@cgi.params["openbd.hidename"][0] == "true")
|
229
|
+
@conf["openbd.default_image"] = @cgi.params["openbd.default_image"][0]
|
230
|
+
|
231
|
+
to_px = lambda do |v|
|
232
|
+
i = v.to_i
|
233
|
+
i > 0 ? i : nil
|
234
|
+
end
|
235
|
+
@conf["openbd.image_width"] =
|
236
|
+
to_px[@cgi.params["openbd.image_width"][0]]
|
237
|
+
@conf["openbd.image_height"] =
|
238
|
+
to_px[@cgi.params["openbd.image_height"][0]]
|
239
|
+
@conf["openbd.detail_image_width"] =
|
240
|
+
to_px[@cgi.params["openbd.detail_image_width"][0]]
|
241
|
+
@conf["openbd.detail_image_height"] =
|
242
|
+
to_px[@cgi.params["openbd.detail_image_height"][0]]
|
243
|
+
|
244
|
+
if @cgi.params["openbd.clearcache"][0] == "true"
|
245
|
+
OpenBD::Cache.new(@cache_path).clear
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
hidename = @conf["amazon.hidename"]
|
250
|
+
<<-EOS
|
251
|
+
<h3>#{h @openbd_label_title}</h3>
|
252
|
+
<p><select name="openbd.hidename">
|
253
|
+
<option value="true"#{" selected" if hidename}>
|
254
|
+
#{h @openbd_label_title_hide}
|
255
|
+
</option>
|
256
|
+
<option value="false"#{" selected" unless hidename}>
|
257
|
+
#{h @openbd_label_title_show}
|
258
|
+
</option>
|
259
|
+
</select></p>
|
260
|
+
|
261
|
+
<h3>#{h @openbd_label_clearcache}</h3>
|
262
|
+
<p><label for="openbd.clearcache">
|
263
|
+
<input type="checkbox" id="openbd.clearcache" name="openbd.clearcache" value="true">
|
264
|
+
#{h @openbd_label_clearcache_desc}
|
265
|
+
</label></p>
|
266
|
+
|
267
|
+
<h3>#{h @openbd_label_default_image}</h3>
|
268
|
+
<p>#{h @openbd_label_default_image_desc}</p>
|
269
|
+
<p><input type="text" name="openbd.default_image" value="#{h @conf["openbd.default_image"]}" size="70"></p>
|
270
|
+
|
271
|
+
<h3>#{h @openbd_label_image_width}</h3>
|
272
|
+
<p>#{h @openbd_label_image_width_desc}</p>
|
273
|
+
<p>
|
274
|
+
<input type="text" name="openbd.image_width" value="#{h @conf["openbd.image_width"]}" size="5">
|
275
|
+
<label for="openbd.image_width">px</label>
|
276
|
+
</p>
|
277
|
+
|
278
|
+
<h3>#{h @openbd_label_image_height}</h3>
|
279
|
+
<p>#{h @openbd_label_image_height_desc}</p>
|
280
|
+
<p>
|
281
|
+
<input type="text" name="openbd.image_height" value="#{h @conf["openbd.image_height"]}" size="5">
|
282
|
+
<label for="openbd.image_height">px</label>
|
283
|
+
</p>
|
284
|
+
|
285
|
+
<h3>#{h @openbd_label_detail_image_width}</h3>
|
286
|
+
<p>#{h @openbd_label_detail_image_width_desc}</p>
|
287
|
+
<p>
|
288
|
+
<input type="text" name="openbd.detail_image_width" value="#{h @conf["openbd.detail_image_width"]}" size="5">
|
289
|
+
<label for="openbd.detail_image_width">px</label>
|
290
|
+
</p>
|
291
|
+
|
292
|
+
<h3>#{h @openbd_label_detail_image_height}</h3>
|
293
|
+
<p>#{h @openbd_label_detail_image_height_desc}</p>
|
294
|
+
<p>
|
295
|
+
<input type="text" name="openbd.detail_image_height" value="#{h @conf["openbd.detail_image_height"]}" size="5">
|
296
|
+
<label for="openbd.detail_image_height">px</label>
|
297
|
+
</p>
|
298
|
+
EOS
|
299
|
+
end
|
300
|
+
|
301
|
+
# Local Variables:
|
302
|
+
# mode: ruby
|
303
|
+
# indent-tabs-mode: t
|
304
|
+
# tab-width: 3
|
305
|
+
# ruby-indent-level: 3
|
306
|
+
# End:
|
data/plugin/puboo.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Original code from tatsu_zine.rb by KADO Masanori <kdmsnr@gmail.com>
|
4
4
|
# You can redistribute it and/or modify it under GPL.
|
5
5
|
#
|
6
|
-
# display book info in
|
6
|
+
# display book info in https://puboo.jp/ like amazon.rb
|
7
7
|
# USAGE: {{puboo 9999}}
|
8
8
|
|
9
9
|
require 'open-uri'
|
@@ -33,12 +33,12 @@ def puboo( id, doc = nil )
|
|
33
33
|
return result
|
34
34
|
end
|
35
35
|
|
36
|
-
link = "
|
37
|
-
doc ||= open( link ).read.force_encoding('UTF-8')
|
38
|
-
title = doc.match(%r|<meta property="og:title"\s*content="(.*)"|).to_a[1]
|
36
|
+
link = "https://puboo.jp/book/#{id}"
|
37
|
+
doc ||= URI.open( link ).read.force_encoding('UTF-8')
|
38
|
+
title = doc.match(%r|<meta property="og:title"\s*content="(.*)"|).to_a[1].split(/|/)[0]
|
39
39
|
image = doc.match(%r|<meta property="og:image"\s*content="(.*)"|).to_a[1]
|
40
|
-
price = doc.match(%r|<
|
41
|
-
author = doc.match(%r
|
40
|
+
price = doc.match(%r|<span\s*class="h2">(.*?)</span>|m).to_a[1]
|
41
|
+
author = doc.match(%r|著: <a.*?>(.*?)</a>|m).to_a[1]
|
42
42
|
|
43
43
|
result = <<-EOS
|
44
44
|
<a class="amazon-detail" href="#{h link}"><span class="amazon-detail">
|
@@ -61,7 +61,7 @@ end
|
|
61
61
|
|
62
62
|
if __FILE__ == $0
|
63
63
|
require 'test/unit'
|
64
|
-
class
|
64
|
+
class TestPuboo < Test::Unit::TestCase
|
65
65
|
def setup
|
66
66
|
@conf = Struct.new("Conf", :secure).new(true)
|
67
67
|
def h(str); str; end
|
@@ -69,14 +69,14 @@ if __FILE__ == $0
|
|
69
69
|
|
70
70
|
def test_puboo
|
71
71
|
expect = <<-EOS
|
72
|
-
<a class="amazon-detail" href="
|
73
|
-
<img class="amazon-detail left" src="
|
72
|
+
<a class="amazon-detail" href="https://puboo.jp/book/70667"><span class="amazon-detail">
|
73
|
+
<img class="amazon-detail left" src="https://img.puboo.jp/667BDD9E-B13E-11E2-82F3-6425FFDA975F_l.jpg"
|
74
74
|
height="150" width="100"
|
75
75
|
alt="入門Puppet - Automate Your Infrastructure">
|
76
76
|
<span class="amazon-detail-desc">
|
77
77
|
<span class="amazon-title">入門Puppet - Automate Your Infrastructure</span><br>
|
78
78
|
<span class="amazon-author">栗林健太郎</span><br>
|
79
|
-
<span class="amazon-price">890
|
79
|
+
<span class="amazon-price">890円</span>
|
80
80
|
</span><br style="clear: left">
|
81
81
|
</span></a>
|
82
82
|
EOS
|
data/plugin/twitter.rb
CHANGED
@@ -1,45 +1,9 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
5
|
-
require 'timeout'
|
6
|
-
require 'time'
|
7
|
-
require 'open-uri'
|
8
|
-
require 'rexml/document'
|
9
|
-
|
10
|
-
@twitter_statuses = []
|
11
|
-
|
12
|
-
if /^(latest|day)$/ =~ @mode then
|
13
|
-
add_header_proc do
|
14
|
-
xml = nil
|
15
|
-
Timeout.timeout( 5 ) do
|
16
|
-
begin
|
17
|
-
xml = open( "http://twitter.com/statuses/user_timeline/#{@conf['twitter.user']}.xml" ){|f| f.read}
|
18
|
-
rescue Exception
|
19
|
-
end
|
20
|
-
end
|
21
|
-
doc = REXML::Document.new( xml ).root if xml
|
22
|
-
if doc then
|
23
|
-
doc.elements.each( 'status' ) do |e|
|
24
|
-
@twitter_statuses << [@conf.to_native( e.elements['text'].text ), Time.parse( e.elements['created_at'].text ).localtime]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
''
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
1
|
+
#
|
2
|
+
# twitter plugin is deprecate
|
3
|
+
#
|
31
4
|
add_body_leave_proc do |date|
|
32
|
-
|
33
|
-
|
34
|
-
today_statuses << [t, d] if d.to_a[3,3] == date.to_a[3,3]
|
35
|
-
end
|
36
|
-
if !today_statuses.empty?
|
37
|
-
r = %Q[<div class="section">]
|
38
|
-
r << %Q[<h3><a href="http://twitter.com/#{@conf['twitter.user']}">Twitter statuses</a></h3>]
|
39
|
-
today_statuses.sort{|a, b| b.last<=>a.last}.each do |t, d|
|
40
|
-
r << %Q[<p><strong>#{CGI::escapeHTML( t )}</strong> (#{d.strftime( '%H:%M:%S' )})</p>]
|
41
|
-
end
|
42
|
-
r << %Q[</div>]
|
5
|
+
if @mode == 'preview'
|
6
|
+
%Q[<p class="message">twitter plugin was deprecated.</p>]
|
43
7
|
else
|
44
8
|
''
|
45
9
|
end
|
data/plugin/twitter_js.rb
CHANGED
@@ -1,59 +1,10 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
5
|
-
if
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
result = <<-HTML
|
10
|
-
<script type="text/javascript"><!--
|
11
|
-
function twitter_cb(a){
|
12
|
-
var f=function(n){return (n<10?'0':'')+n};
|
13
|
-
for(var i=0,l=a.length;i<l;i++){
|
14
|
-
var d=new Date(a[i]['created_at'].replace('+0000','UTC'));
|
15
|
-
var id='twitter_statuses_'+f(d.getFullYear())+f(d.getMonth()+1)+f(d.getDate());
|
16
|
-
var e=document.getElementById(id);
|
17
|
-
if(!e) continue;
|
18
|
-
if(!e.innerHTML) e.innerHTML='<h3><a href="http://twitter.com/#{h twitter_user}">Twitter statuses</a></h3>';
|
19
|
-
e.innerHTML+='<p><strong>'+a[i]['text']+'</strong> ('+f(d.getHours())+':'+f(d.getMinutes())+':'+f(d.getSeconds())+')</p>';
|
20
|
-
}
|
21
|
-
}
|
22
|
-
function twitter_js(){
|
23
|
-
var e=document.createElement('script');
|
24
|
-
e.type='text/javascript';
|
25
|
-
e.src='http://twitter.com/statuses/user_timeline/#{h twitter_user}.json?callback=twitter_cb&count=20';
|
26
|
-
document.documentElement.appendChild(e);
|
27
|
-
}
|
28
|
-
if(window.addEventListener){
|
29
|
-
window.addEventListener('load',twitter_js,false);
|
30
|
-
}else if(window.attachEvent){
|
31
|
-
window.attachEvent('onload',twitter_js);
|
32
|
-
}else{
|
33
|
-
window.onload=twitter_js;
|
34
|
-
}
|
35
|
-
// --></script>
|
36
|
-
HTML
|
37
|
-
result.gsub( /^\t\t/, '' )
|
38
|
-
end
|
39
|
-
|
40
|
-
add_body_leave_proc do |date|
|
41
|
-
result = <<-HTML
|
42
|
-
<div id="twitter_statuses_#{date.strftime( "%Y%m%d" )}" class="section"></div>
|
43
|
-
HTML
|
44
|
-
result.gsub( /^\t\t/, '' )
|
45
|
-
end
|
1
|
+
#
|
2
|
+
# twitter_js plugin is deprecate
|
3
|
+
#
|
4
|
+
add_body_leave_proc do |date|
|
5
|
+
if @mode == 'preview'
|
6
|
+
%Q[<p class="message">twitter_js plugin was deprecated.</p>]
|
7
|
+
else
|
8
|
+
''
|
46
9
|
end
|
47
10
|
end
|
48
|
-
|
49
|
-
add_conf_proc( 'twitter_js', 'Twitter' ) do
|
50
|
-
|
51
|
-
if @mode == 'saveconf' then
|
52
|
-
@conf['twitter.user'] = @cgi.params['twitter.user'][0]
|
53
|
-
end
|
54
|
-
|
55
|
-
<<-HTML
|
56
|
-
<h3 class="subtitle">Account Name</h3>
|
57
|
-
<p><input name="twitter.user" value="#{h @conf['twitter.user']}"></p>
|
58
|
-
HTML
|
59
|
-
end
|
data/spec/spec_helper.rb
CHANGED
@@ -200,7 +200,7 @@ def fake_plugin( name_sym, cgi=nil, base=nil, &block )
|
|
200
200
|
plugin.instance_variable_set(:@cache_path, @cache_path)
|
201
201
|
|
202
202
|
plugin.instance_eval do
|
203
|
-
eval( File.
|
203
|
+
eval( File.open(file_path, 'r:utf-8').read, binding,
|
204
204
|
"(#{File.basename(file_path)})", 1 )
|
205
205
|
end
|
206
206
|
plugin_sym = plugin_name.to_sym
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdiary-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tDiary contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tdiary
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coderay
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +129,21 @@ dependencies:
|
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '0'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
132
|
+
name: ruby-debug-ide
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: debase
|
119
147
|
requirement: !ruby/object:Gem::Requirement
|
120
148
|
requirements:
|
121
149
|
- - ">="
|
@@ -194,6 +222,7 @@ files:
|
|
194
222
|
- js/editor.js
|
195
223
|
- js/flickr.js
|
196
224
|
- js/google_photos.js
|
225
|
+
- js/gyazo.js
|
197
226
|
- js/hide_sidebar_smartphone.js
|
198
227
|
- js/image_ex.js
|
199
228
|
- js/jquery.socialbutton.js
|
@@ -268,6 +297,7 @@ files:
|
|
268
297
|
- plugin/google_sitemaps.rb
|
269
298
|
- plugin/google_universal_analytics.rb
|
270
299
|
- plugin/google_webmaster.rb
|
300
|
+
- plugin/gyazo.rb
|
271
301
|
- plugin/hatena_bookmark_nocomment.rb
|
272
302
|
- plugin/hatena_star.rb
|
273
303
|
- plugin/hb_footer.rb
|
@@ -290,6 +320,7 @@ files:
|
|
290
320
|
- plugin/ja/livedoor_weather.rb
|
291
321
|
- plugin/ja/microsummary.rb
|
292
322
|
- plugin/ja/nicovideo.rb
|
323
|
+
- plugin/ja/openbd.rb
|
293
324
|
- plugin/ja/openid.rb
|
294
325
|
- plugin/ja/section_footer.rb
|
295
326
|
- plugin/ja/section_footer2.rb
|
@@ -319,6 +350,7 @@ files:
|
|
319
350
|
- plugin/notify_miniblog.rb
|
320
351
|
- plugin/ogp.rb
|
321
352
|
- plugin/ohmsha_estore.rb
|
353
|
+
- plugin/openbd.rb
|
322
354
|
- plugin/openid.rb
|
323
355
|
- plugin/opensearch_ad.rb
|
324
356
|
- plugin/picasa.rb
|
@@ -401,7 +433,6 @@ files:
|
|
401
433
|
- spec/rcov.opts
|
402
434
|
- spec/spec_helper.rb
|
403
435
|
- spec/title_anchor_spec.rb
|
404
|
-
- spec/twitter_js_spec.rb
|
405
436
|
- spec/youtube_spec.rb
|
406
437
|
- style/hatena_style.rb
|
407
438
|
- style/markdown_style.rb
|
@@ -541,5 +572,4 @@ test_files:
|
|
541
572
|
- spec/rcov.opts
|
542
573
|
- spec/spec_helper.rb
|
543
574
|
- spec/title_anchor_spec.rb
|
544
|
-
- spec/twitter_js_spec.rb
|
545
575
|
- spec/youtube_spec.rb
|
data/spec/twitter_js_spec.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
describe "twitter_js plugin" do
|
6
|
-
def setup_twitter_js_plugin(mode, user_id)
|
7
|
-
fake_plugin(:twitter_js) { |plugin|
|
8
|
-
plugin.mode = mode
|
9
|
-
plugin.conf['twitter.user'] = user_id
|
10
|
-
plugin.date = Time.parse("20080124")
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "should render javascript and div tag in day" do
|
15
|
-
before do
|
16
|
-
@plugin = setup_twitter_js_plugin("day", "123456789")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "for header" do
|
20
|
-
snippet = @plugin.header_proc
|
21
|
-
expect(snippet).to eq(expected_html_header_snippet("123456789"))
|
22
|
-
end
|
23
|
-
|
24
|
-
it "for body leave" do
|
25
|
-
snippet = @plugin.body_leave_proc(Time.parse("20080124"))
|
26
|
-
expect(snippet).to eq(expected_html_body_snippet)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "should render javascript and div tag in latest" do
|
31
|
-
before do
|
32
|
-
@plugin = setup_twitter_js_plugin("latest", "123456789")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "for header" do
|
36
|
-
snippet = @plugin.header_proc
|
37
|
-
expect(snippet).to eq(expected_html_header_snippet("123456789"))
|
38
|
-
end
|
39
|
-
|
40
|
-
it "for body leave" do
|
41
|
-
snippet = @plugin.body_leave_proc(Time.parse("20080124"))
|
42
|
-
expect(snippet).to eq(expected_html_body_snippet)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "should not render in edit" do
|
47
|
-
before do
|
48
|
-
@plugin = setup_twitter_js_plugin("edit", "123456789")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "for header" do
|
52
|
-
snippet = @plugin.header_proc
|
53
|
-
expect(snippet).to be_empty
|
54
|
-
end
|
55
|
-
|
56
|
-
it "for body leave" do
|
57
|
-
snippet = @plugin.body_leave_proc(Time.parse("20080124"))
|
58
|
-
expect(snippet).to be_empty
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "should not render when user_id is empty" do
|
63
|
-
before do
|
64
|
-
@plugin = setup_twitter_js_plugin("edit", "")
|
65
|
-
end
|
66
|
-
|
67
|
-
it "for header" do
|
68
|
-
snippet = @plugin.header_proc
|
69
|
-
expect(snippet).to be_empty
|
70
|
-
end
|
71
|
-
|
72
|
-
it "for body leave" do
|
73
|
-
snippet = @plugin.body_leave_proc(Time.parse("20080124"))
|
74
|
-
expect(snippet).to be_empty
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def expected_html_header_snippet(user_id)
|
79
|
-
expected = <<-EXPECTED
|
80
|
-
<script type="text/javascript"><!--
|
81
|
-
function twitter_cb(a){
|
82
|
-
var f=function(n){return (n<10?'0':'')+n};
|
83
|
-
for(var i=0,l=a.length;i<l;i++){
|
84
|
-
var d=new Date(a[i]['created_at'].replace('+0000','UTC'));
|
85
|
-
var id='twitter_statuses_'+f(d.getFullYear())+f(d.getMonth()+1)+f(d.getDate());
|
86
|
-
var e=document.getElementById(id);
|
87
|
-
if(!e) continue;
|
88
|
-
if(!e.innerHTML) e.innerHTML='<h3><a href="http://twitter.com/#{user_id}">Twitter statuses</a></h3>';
|
89
|
-
e.innerHTML+='<p><strong>'+a[i]['text']+'</strong> ('+f(d.getHours())+':'+f(d.getMinutes())+':'+f(d.getSeconds())+')</p>';
|
90
|
-
}
|
91
|
-
}
|
92
|
-
function twitter_js(){
|
93
|
-
var e=document.createElement('script');
|
94
|
-
e.type='text/javascript';
|
95
|
-
e.src='http://twitter.com/statuses/user_timeline/#{user_id}.json?callback=twitter_cb&count=20';
|
96
|
-
document.documentElement.appendChild(e);
|
97
|
-
}
|
98
|
-
if(window.addEventListener){
|
99
|
-
window.addEventListener('load',twitter_js,false);
|
100
|
-
}else if(window.attachEvent){
|
101
|
-
window.attachEvent('onload',twitter_js);
|
102
|
-
}else{
|
103
|
-
window.onload=twitter_js;
|
104
|
-
}
|
105
|
-
// --></script>
|
106
|
-
EXPECTED
|
107
|
-
expected.gsub(/^\t/, '').chomp
|
108
|
-
end
|
109
|
-
|
110
|
-
def expected_html_body_snippet
|
111
|
-
expected = <<-HTML
|
112
|
-
<div id="twitter_statuses_20080124" class="section"></div>
|
113
|
-
HTML
|
114
|
-
expected.gsub( /^\t/, '' ).chomp
|
115
|
-
end
|
116
|
-
end
|