tdiary-contrib 4.0.2.1 → 4.0.3

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: 85cf1d5815f8a25ac6c6d5c5ba9cb4fc92203dfa
4
- data.tar.gz: 24e64b73452bf435e9241af42a403f3d16ec9a1f
3
+ metadata.gz: b93a4e4a623dc81cccbe122dcecd09f37adf408b
4
+ data.tar.gz: ebed4176090ce9d2046b34b9273aa3e85d873d4b
5
5
  SHA512:
6
- metadata.gz: be8344e9e8a190022cc3f5e514357e85e9638174ffe93a9bb09028734bea7e5e2a59ec75484099b5b89ddad3297dacc32f122081640947214ebc23429e2b1877
7
- data.tar.gz: aa811bccb9496a12411a6f0ac0966f73574687184a544acde2a08136b42c3ab09704f4a6b5f74199fee565489966dbe29ccef222b1714b2aa2a09f4c67d26c91
6
+ metadata.gz: 9986ae7afd37e0605113b81b641a5e5e0dbc52c01b971e9e54d42fdca9655f9305f31927be6d9be2b7df869642964d0b46181d8f01f75477df11682669fb0d91
7
+ data.tar.gz: 2eecb6b945e59647fa851234ec610c0febf7e7ef4a2342bc2165014c75acc6fd8c2b11988a271c4cc1edd961725723f1d381140ffe4c36b41d067f54b67620fc
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'tdiary', '4.0.2'
4
4
 
5
5
  gem 'rake'
6
- gem 'rspec'
6
+ gem 'rspec', '~> 3.0.0.beta2'
7
7
 
8
8
  platforms :ruby_18 do
9
9
  gem 'json'
data/Gemfile.lock CHANGED
@@ -2,19 +2,23 @@ GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.2.5)
5
- docile (1.1.1)
5
+ docile (1.1.3)
6
6
  json (1.8.1)
7
- multi_json (1.8.2)
8
- rake (10.1.0)
7
+ multi_json (1.8.4)
8
+ rake (10.1.1)
9
9
  rcov (1.0.0)
10
- rspec (2.14.1)
11
- rspec-core (~> 2.14.0)
12
- rspec-expectations (~> 2.14.0)
13
- rspec-mocks (~> 2.14.0)
14
- rspec-core (2.14.7)
15
- rspec-expectations (2.14.4)
16
- diff-lcs (>= 1.1.3, < 2.0)
17
- rspec-mocks (2.14.4)
10
+ rspec (3.0.0.beta2)
11
+ rspec-core (= 3.0.0.beta2)
12
+ rspec-expectations (= 3.0.0.beta2)
13
+ rspec-mocks (= 3.0.0.beta2)
14
+ rspec-core (3.0.0.beta2)
15
+ rspec-support (= 3.0.0.beta2)
16
+ rspec-expectations (3.0.0.beta2)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (= 3.0.0.beta2)
19
+ rspec-mocks (3.0.0.beta2)
20
+ rspec-support (= 3.0.0.beta2)
21
+ rspec-support (3.0.0.beta2)
18
22
  simplecov (0.8.2)
19
23
  docile (~> 1.1.0)
20
24
  multi_json
@@ -32,6 +36,6 @@ DEPENDENCIES
32
36
  json
33
37
  rake
34
38
  rcov
35
- rspec
39
+ rspec (~> 3.0.0.beta2)
36
40
  simplecov
37
41
  tdiary (= 4.0.2)
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'tdiary/extensions'
3
+
4
+ module TDiary
5
+ module Extensions
6
+ class Contrib
7
+ def self.sp_path
8
+ File.join(TDiary::Contrib.root, 'plugin')
9
+ end
10
+
11
+ def self.assets_path
12
+ File.join(TDiary::Contrib.root, 'js')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,20 +1,10 @@
1
- require 'tdiary'
2
- require 'tdiary/application'
1
+ # -*- coding: utf-8 -*-
2
+ require 'extensions/contrib'
3
3
 
4
4
  module TDiary
5
5
  class Contrib
6
6
  def self.root
7
7
  File.expand_path('../..', __FILE__)
8
8
  end
9
-
10
- class Plugin
11
- def self.setup(sp_path)
12
- sp_path << File.join(TDiary::Contrib.root, 'plugin')
13
- end
14
- end
15
- end
16
-
17
- Application.configure do
18
- config.assets_paths << File.join(TDiary::Contrib.root, 'js')
19
9
  end
20
10
  end
@@ -1,5 +1,5 @@
1
1
  module TDiary
2
- module Contrib
3
- VERSION = "4.0.2.1"
2
+ class Contrib
3
+ VERSION = "4.0.3"
4
4
  end
5
5
  end
data/plugin/coderay.rb ADDED
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # coderay.rb - easy syntax highlighting for selected languages
4
+ # refer to the URL below.
5
+ # http://coderay.rubychan.de/
6
+ #
7
+ # Copyright (C) 2013, tamoot <tamoot+tdiary@gmail.com>
8
+ # You can redistribute it and/or modify it under GPL2.
9
+ #
10
+
11
+ require 'cgi'
12
+ require 'erb'
13
+ require 'coderay'
14
+
15
+ @coderay_default_css ||= ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet
16
+
17
+ def coderay(lang, text, options = {})
18
+ html = ::CodeRay.scan(text, lang).html(:line_numbers => :inline, :bold_every => false, :line_number_anchors => false)
19
+ %Q|<div class="CodeRay"><pre>#{html}</pre></div>|
20
+ end
21
+
22
+ add_header_proc do
23
+ coderay_css = ''
24
+ if @conf['coderay.css.url'] && @conf['coderay.css.url'].size > 0
25
+ coderay_css = %Q|<link rel="stylesheet" href="#{h @conf['coderay.css.url']}" type="text/css" media="all">|
26
+ else
27
+ coderay_css = <<-STYLE
28
+ <style type="text/css"><!--
29
+ #{@coderay_default_css}
30
+ -->
31
+ </style>
32
+ STYLE
33
+ end
34
+
35
+ coderay_css
36
+ end
37
+
38
+ add_conf_proc( 'coderay', 'CodeRay' ) do
39
+ if @mode == 'saveconf' then
40
+ @conf['coderay.css.url'] = @cgi.params['coderay.css.url'][0]
41
+
42
+ end
43
+
44
+ coderay_conf = <<-HTML
45
+ <h3 class="subtitle">custom style</h3>
46
+
47
+ <p>The stylesheet path is used instead of CodeRay default. </p>
48
+ <p>Path: <input name="coderay.css.url" value="#{h @conf['coderay.css.url']}" size="70"></p>
49
+ <pre>
50
+ sample:
51
+ #{CGI::escape_html('<link rel="stylesheet" href="/your/tdiary/path/coderay.css" type="text/css" media="all">')}
52
+ </pre>
53
+
54
+
55
+ <h4>Print default stylesheet of CodeRay</h4>
56
+ <p>1. The coderay command installed along with the CodeRay gem can print out a stylesheet for you.</p>
57
+ <pre>
58
+ bundle exec coderay stylesheet > /your/tdiary/path/coderay.css
59
+ </pre>
60
+ <p>2. Edit your stylesheet and modify permissions.</p>
61
+
62
+ HTML
63
+
64
+ coderay_conf
65
+
66
+ end
67
+
68
+ # Local Variables:
69
+ # mode: ruby
70
+ # indent-tabs-mode: t
71
+ # tab-width: 3
72
+ # ruby-indent-level: 3
73
+ # End:
74
+ # vim: ts=3
data/plugin/image_ex.rb CHANGED
@@ -275,9 +275,17 @@ add_form_proc do |date|
275
275
  if imageex_useresize == 1 or imageex_useresize == 2
276
276
  open(image_file,"rb") do |fh|
277
277
  img = ImageSize.new(fh.read)
278
- width = img.get_width
279
- height = img.get_height
280
- orig_type = img.get_type
278
+ begin
279
+ # old image_size.rb
280
+ width = img.get_width
281
+ height = img.get_height
282
+ orig_type = img.get_type
283
+ rescue NoMethodError
284
+ # image_size gem
285
+ width = img.width
286
+ height = img.height
287
+ orig_type = (img.format || "OTHER").to_s.upcase
288
+ end
281
289
  if imageex_converttype == 0
282
290
  new_type = "jpg"
283
291
  elsif imageex_converttype == 1
@@ -383,23 +391,13 @@ add_form_proc do |date|
383
391
  r << %Q[
384
392
  <script type="text/javascript">
385
393
  <!--
386
- var elem=null
394
+ var elem=null;
387
395
  function ins(val){
388
396
  elem.value+=val
389
397
  }
390
- window.onload=function(){
391
- for(var i=0;i<document.forms.length;i++){
392
- for(var j=0;j<document.forms[i].elements.length;j++){
393
- var e=document.forms[i].elements[j]
394
- if(e.type&&e.type=="textarea"){
395
- if(elem==null){
396
- elem=e
397
- }
398
- e.onfocus=new Function("elem=this")
399
- }
400
- }
401
- }
402
- }
398
+ $(document).ready(function(){
399
+ $("textarea").focus(function() { elem = this; });
400
+ });
403
401
  //-->
404
402
  </script>
405
403
  ]
@@ -26,7 +26,7 @@ class MakeRssCategory < MakeRssFull
26
26
  def file
27
27
  f = @conf['makerss.category.file'] || 'category.rdf'
28
28
  f = 'category.rdf' if f.length == 0
29
- f
29
+ f =~ %r|^/| ? f : "#{document_root}/#{f}"
30
30
  end
31
31
 
32
32
  def write( encoder )
@@ -40,4 +40,4 @@ class MakeRssCategory < MakeRssFull
40
40
  end
41
41
  end
42
42
 
43
- @makerss_rsses << MakeRssCategory::new( @conf )
43
+ @makerss_rsses << MakeRssCategory::new( @conf, @cgi )
@@ -18,7 +18,7 @@ class MakeRssComments < MakeRssFull
18
18
  def file
19
19
  f = @conf['makerss.no_comments.file'] || 'comments.rdf'
20
20
  f = 'comments.rdf' if f.length == 0
21
- f
21
+ f =~ %r|^/| ? f : "#{document_root}/#{f}"
22
22
  end
23
23
 
24
24
  def write( encoder )
@@ -32,4 +32,4 @@ class MakeRssComments < MakeRssFull
32
32
  end
33
33
  end
34
34
 
35
- @makerss_rsses << MakeRssComments::new( @conf )
35
+ @makerss_rsses << MakeRssComments::new( @conf, @cgi )
@@ -0,0 +1,104 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # nhk_program_info.rb - embedded NHK program information
4
+ # refer to following URL.
5
+ # http://api-portal.nhk.or.jp/ja
6
+ #
7
+ # Copyright (C) 2014, tamoot <tamoot+tdiary@gmail.com>
8
+ # You can redistribute it and/or modify it under GPL2.
9
+ #
10
+
11
+ require 'json'
12
+ require 'date'
13
+ require 'timeout'
14
+ require 'open-uri'
15
+
16
+
17
+ def nhk_program_info(id, service, area = nil)
18
+
19
+ area = @conf['nhk_api.default.area'] if area.nil? || area == ""
20
+
21
+ json = nil
22
+ begin
23
+ json = call_nhk_json(id, service, area)
24
+ rescue
25
+ return %Q|<p>#{__FILE__}: error, #{$!}</p>|
26
+ end
27
+
28
+ stime = DateTime::parse(json["start_time"]).strftime("%Y/%m/%d %H:%M:%S")
29
+ etime = DateTime::parse(json["end_time"]).strftime("%Y/%m/%d %H:%M:%S")
30
+
31
+ return <<-PROGRAM_HTML
32
+ <div class="amazon-detail">
33
+ <a href="#{json["program_url"]}">
34
+ <img src="#{json["program_logo"]["url"]}" alt="#{@conf.to_native json["title"]}" class="amazon-detail left">
35
+ <div class="amazon-detail-desc">
36
+ <span class="amazon-title">#{h json["service"]["name"]} - #{h json["title"]}</span><br><br>
37
+ <span class="amazon-title">#{h json["subtitle"]}</span><br><br>
38
+ <span class="amazon-price">#{h stime} - #{etime}</span><br>
39
+ <span class="amazon-price">#{h '情報提供:NHK'}</span>
40
+ </div>
41
+ <br style="clear: left">
42
+ </a>
43
+ </div>
44
+ PROGRAM_HTML
45
+
46
+ end
47
+
48
+ def call_nhk_json(id, service, area)
49
+
50
+ data = nil
51
+ nhk_endpoint = "http://api.nhk.or.jp/v1/pg/info/#{area}/#{service}/#{id}.json?key=#{@conf['nhk_api.id']}"
52
+
53
+ nhk_cache_path = "#{@cache_path}/nhk"
54
+ Dir::mkdir(nhk_cache_path) unless File::directory?(nhk_cache_path)
55
+
56
+ cache = "#{nhk_cache_path}/#{area}_#{service}_#{id}.json"
57
+ begin
58
+ data = File.read(cache)
59
+ File::delete(cache) if Time::now > File::mtime( cache ) + 60*60*24*30
60
+
61
+ rescue
62
+ open_param = [nhk_endpoint]
63
+ open_param << {:proxy => "http://#{@conf['proxy']}"} if @conf['proxy']
64
+
65
+ status = nil
66
+ data = nil
67
+ timeout(10) do
68
+ open(*open_param){ |ff| data = ff.read; status = ff.status[0] }
69
+ end
70
+ raise "API Error" if status.to_s != '200'
71
+ File::open(cache, 'wb') {|f| f.write(data) }
72
+
73
+
74
+ end
75
+
76
+ JSON::parse(data)['list'][service][0]
77
+ end
78
+
79
+ add_conf_proc( 'nhk', 'NHK API' ) do
80
+ if @mode == 'saveconf' then
81
+ @conf['nhk_api.id'] = @cgi.params['nhk_api.id'][0]
82
+ @conf['nhk_api.default.area'] = @cgi.params['nhk_api.default.area'][0]
83
+ end
84
+
85
+ <<-HTML
86
+ <h3 class="subtitle">API key</h3>
87
+ <p><input name="nhk_api.id" value="#{h @conf['nhk_api.id']}" size="70"></p>
88
+ <p>Register your tDiary and get API key.</p>
89
+ <a href="http://www2.nhk.or.jp/api/">Go NHK API settings.</a></p>
90
+ <h3 class="subtitle">Default Area</h3>
91
+ <p><input name="nhk_api.default.area" value="#{h @conf['nhk_api.default.area']}" size="70"></p>
92
+ <a href="http://www2.nhk.or.jp/api/">Refer NHK API settings.</a></p>
93
+ HTML
94
+
95
+ end
96
+
97
+ # Local Variables:
98
+ # mode: ruby
99
+ # indent-tabs-mode: t
100
+ # tab-width: 3
101
+ # ruby-indent-level: 3
102
+ # End:
103
+ # vim: ts=3
104
+
data/plugin/profile.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # profile(id[, service = :twitter])
6
6
  # - id: user ID for profile service
7
7
  # - service: profile service (default is :twitter)
8
- # Choose from :github, :twitter, :friendfeed, :iddy
8
+ # Choose from :github, :twitter, :friendfeed
9
9
  #
10
10
  # Copyright (C) 2009 by MATSUOKA Kohei < http://www.machu.jp/ >
11
11
  # Distributed under the GPL.
@@ -132,23 +132,9 @@ module ::Profile
132
132
  end
133
133
  end
134
134
 
135
- # iddy.jp
136
- # this class is based on iddy.rb
135
+ # iddy.jp, for backward compatibility
137
136
  class Iddy < Base
138
- ######################################################################
139
- # If you will modify or release another version of this code,
140
- # please get your own application key from iddy.jp and replace below.
141
- ######################################################################
142
- API_KEY = '9262ea8ffba962aabb4f1a1d3f1cfa953b11aa23' unless defined? API_KEY
143
-
144
- property :name, '//response/users/user/accountname'
145
- property :image, '//response/users/user/imageurl'
146
- property :description, '/response/users/user/profile'
147
- endpoint {|id| "http://iddy.jp/api/user/?apikey=#{API_KEY}&accountname=#{id}" }
148
-
149
- def link
150
- "http://iddy.jp/profile/#{@id}/"
151
- end
137
+ # dummy class
152
138
  end
153
139
 
154
140
  # gravatar.com
@@ -181,10 +167,9 @@ def profile(id, service = :twitter, options = {})
181
167
  :twitter => Profile::Service::Twitter,
182
168
  :github => Profile::Service::GitHub,
183
169
  :friendfeed => Profile::Service::FriendFeed,
184
- :iddy => Profile::Service::Iddy,
185
170
  :gravatar => Profile::Service::Gravatar,
186
171
  :hatena => Profile::Service::Hatena,
187
- }[service.to_s.downcase.to_sym]
172
+ }[service.to_s.downcase.to_sym] || Profile::Service::Twitter
188
173
 
189
174
  # TODO: create cache manager class
190
175
 
@@ -9,6 +9,7 @@
9
9
  #
10
10
  # @options['search-bing.appid'] : Your Bing AppId
11
11
  # @options['search.result_filter'] : your dialy's URL format of DAY mode into Regexp.
12
+ # @options['search-bing.base'] : Base URI of your diary (for debugging)
12
13
  #
13
14
 
14
15
  require 'timeout'
@@ -32,11 +33,16 @@ end
32
33
  def search_bing_api( q, start = 0 )
33
34
  appid = @conf['search-bing.appid']
34
35
 
35
- u = 'https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/v1/Web'
36
+ u = 'https://api.datamarket.azure.com/Bing/SearchWeb/v1/Web'
36
37
  u << "?Query=%27#{q}%27&Options=%27EnableHighlighting%27&$top=50&$skip=#{start}&$format=Json"
37
38
  uri = URI( u )
38
39
 
39
- open( uri, {:http_basic_authentication => [appid, appid]} ).read
40
+ begin
41
+ open( uri, {:http_basic_authentication => [appid, appid]} ).read
42
+ rescue SecurityError
43
+ ### FIX ME: mysterious error at 1st access to the API
44
+ open( uri, {:http_basic_authentication => [appid, appid]} ).read
45
+ end
40
46
 
41
47
  ### FIX ME: this code failed on Timeout error, temporary using open-uri above.
42
48
  # px_host, px_port = (@conf['proxy'] || '').split( /:/ )
@@ -58,12 +64,10 @@ def search_result
58
64
  start = CGI::unescape( @cgi.params['start'][0] || '0' ).to_i
59
65
 
60
66
  begin
61
- uri = URI::parse( @conf.base_url )
62
- #uri = URI::parse( 'http://sho.tdiary.net/' ) ### FOR DEBUGGING ###
67
+ uri = URI::parse( @conf['search-bing.base'] || @conf.base_url )
63
68
  q = "#{query} site:#{uri.host}"
64
69
  q << %Q| inurl:"#{uri.path}"| unless uri.path == '/'
65
- xml = search_bing_api( u( q.untaint ), start )
66
- json = JSON::parse( xml )
70
+ json = JSON::parse(search_bing_api(u(q.untaint), start))
67
71
  rescue Net::HTTPError
68
72
  return %Q|<p class="message">#$!</p>|
69
73
  end