mediawiki_tool 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wikicalendar ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: UTF-8
3
+
4
+ require 'mediawiki_tool'
5
+
6
+ puts 'Type your name: '
7
+ MediawikiTool.user_name = gets.strip
8
+ puts MediawikiTool::Calendar.month
data/lib/ext/string.rb ADDED
@@ -0,0 +1,34 @@
1
+ class String
2
+ def wiki_pre
3
+ lines.map do |line|
4
+ ' ' + line
5
+ end.join
6
+ end
7
+
8
+ def wiki_italic
9
+ "''" + self + "''"
10
+ end
11
+
12
+ def wiki_bold
13
+ "'''" + self + "'''"
14
+ end
15
+
16
+ def wiki_td(options={})
17
+ wiki_table_element '|', options
18
+ end
19
+
20
+ def wiki_th(options={})
21
+ wiki_table_element '!', options
22
+ end
23
+
24
+ private
25
+
26
+ def wiki_table_element(symbol, options)
27
+ element = symbol
28
+ element += options.map do |key, value|
29
+ "#{key}='#{value}'"
30
+ end.join(' ')
31
+ element += '|' unless options.empty?
32
+ element + self
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'date'
4
+ require 'active_support/core_ext'
5
+ require 'ext/string'
6
+
7
+ class MediawikiTool::Calendar
8
+ def self.month(month = Time.now.month, year = Time.now.year)
9
+ calendar_first = Date.new(year,month).beginning_of_week
10
+ calendar_last = Date.new(year,month,-1).end_of_week
11
+
12
+ table_head = Date::ABBR_DAYNAMES.rotate.map(&:upcase).unshift('').map(&:wiki_th).join("\n")
13
+
14
+ table_lines = (calendar_first..calendar_last).group_by(&:cweek).map do |_, days|
15
+ line_head = week_link(days.first).wiki_th
16
+ line_elements = days.map do |day|
17
+ ((day.month==month) ? day_link(day) : '').wiki_td(align: 'middle')
18
+ end
19
+ line_elements.unshift(line_head).join("\n")
20
+ end
21
+
22
+ "{|\n" + table_lines.unshift(table_head).join("\n|-\n") + "\n|}"
23
+ end
24
+
25
+ private
26
+
27
+ def self.day_link(date)
28
+ "[[#{MediawikiTool.user_name} 日志 %04d.%02d.%02d|%02d]]" % [date.year, date.month, date.day, date.day]
29
+ end
30
+
31
+ def self.week_link(date)
32
+ "[[#{MediawikiTool.user_name} 周报 %04d 第%02d周|Week%02d]]" % [date.cwyear, date.cweek, date.cweek]
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ class MediawikiTool
2
+ def self.user_name
3
+ @@user_name
4
+ end
5
+
6
+ def self.user_name=(name)
7
+ @@user_name = name unless name.blank?
8
+ end
9
+
10
+ private
11
+
12
+ @@user_name = 'USER_NAME'
13
+ end
14
+
15
+ require 'mediawiki_tool/calendar'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mediawiki_tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jun Zhou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: i18n
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Generate calendar in MediaWiki syntax
47
+ email: junzhou@pinepara.info
48
+ executables:
49
+ - wikicalendar
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - ./lib/mediawiki_tool.rb
54
+ - ./lib/ext/string.rb
55
+ - ./lib/mediawiki_tool/calendar.rb
56
+ - bin/wikicalendar
57
+ homepage: http://rubygems.org/gems/mediawiki_tool
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Toolkits to help formatting text in MediaWiki syntax
81
+ test_files: []
82
+ has_rdoc: