packnga 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,182 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 yoshihara haruka <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "rubyforge"
19
+
20
+ module Packnga
21
+ # This class creates release tasks.
22
+ #
23
+ # Release tasks tag current version and install gem for test.
24
+ # It also define tasks to upload rubyforge whether option.
25
+ #
26
+ # @since 0.9.0
27
+ class ReleaseTask
28
+ include Rake::DSL
29
+
30
+ # This attribute is path of HTML files written version and release date.
31
+ # @param [String] path of HTML files
32
+ attr_writer :index_html_dir
33
+ # This attribute is path of base directory of document.
34
+ # @param [String] path of base directory of document
35
+ attr_writer :base_dir
36
+ # Defines task for preparing to release.
37
+ # Defined tasks update version and release-date in index files
38
+ # and tag in git.
39
+ # If you set rubyforge_project of Jeweler::Task.new with its given block,
40
+ # it also define tasks to update rubyforge.
41
+ # @param [Jeweler::Task] spec created by Jeweler::Task.new.
42
+ def initialize(spec)
43
+ @spec = spec
44
+ @index_html_dir = nil
45
+ @rubyforge = nil
46
+ yield(self) if block_given?
47
+ set_default_values
48
+ define_tasks
49
+ end
50
+
51
+ private
52
+ def html_base_dir
53
+ @base_dir + "html"
54
+ end
55
+
56
+ def html_reference_dir
57
+ html_base_dir + @spec.name
58
+ end
59
+
60
+ def set_default_values
61
+ @index_html_dir ||= "doc/html"
62
+ @base_dir ||= Pathname.new("doc")
63
+ end
64
+
65
+ def define_tasks
66
+ namespace :release do
67
+ define_info_task
68
+ define_tag_task
69
+ define_rubyforge_tasks
70
+ end
71
+ end
72
+
73
+ def define_info_task
74
+ namespace :info do
75
+ desc "update version in index HTML."
76
+ task :update do
77
+ old_version = ENV["OLD_VERSION"]
78
+ old_release_date = ENV["OLD_RELEASE_DATE"]
79
+ new_release_date = ENV["RELEASE_DATE"] || Time.now.strftime("%Y-%m-%d")
80
+ new_version = ENV["VERSION"]
81
+
82
+ empty_options = []
83
+ empty_options << "OLD_VERSION" if old_version.nil?
84
+ empty_options << "OLD_RELEASE_DATE" if old_release_date.nil?
85
+
86
+ unless empty_options.empty?
87
+ raise ArgumentError, "Specify option(s) of #{empty_options.join(", ")}."
88
+ end
89
+ @index_html_dir = Pathname(@index_html_dir)
90
+ indexes = [@index_html_dir + "index.html", @index_html_dir + "index.html.ja"]
91
+ indexes.each do |index|
92
+ content = replaced_content = File.read(index)
93
+ [[old_version, new_version],
94
+ [old_release_date, new_release_date]].each do |old, new|
95
+ replaced_content = replaced_content.gsub(/#{Regexp.escape(old)}/, new)
96
+ if /\./ =~ old
97
+ old_underscore = old.gsub(/\./, '-')
98
+ new_underscore = new.gsub(/\./, '-')
99
+ replaced_content =
100
+ replaced_content.gsub(/#{Regexp.escape(old_underscore)}/,
101
+ new_underscore)
102
+ end
103
+ end
104
+
105
+ next if replaced_content == content
106
+ File.open(index, "w") do |output|
107
+ output.print(replaced_content)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ def define_tag_task
115
+ desc "Tag the current revision."
116
+ task :tag do
117
+ version = @spec.version
118
+ sh("git tag -a #{version} -m 'release #{version}!!!'")
119
+ end
120
+ end
121
+
122
+ def define_rubyforge_tasks
123
+ return if @spec.rubyforge_project.nil?
124
+ @rubyforge = RubyForge.new
125
+ @rubyforge.configure
126
+ define_reference_task
127
+ define_html_task
128
+ define_publish_task
129
+ define_upload_tasks
130
+ end
131
+
132
+ def define_reference_task
133
+ namespace :reference do
134
+ desc "Upload document to rubyforge."
135
+ task :publish => [:generate, "reference:publication:prepare"] do
136
+ rsync_to_rubyforge(@spec, "#{html_reference_dir}/", @spec.name)
137
+ end
138
+ end
139
+ end
140
+
141
+ def define_html_task
142
+ namespace :html do
143
+ desc "Publish HTML to Web site."
144
+ task :publish do
145
+ rsync_to_rubyforge(@spec, "#{html_base_dir}/", "")
146
+ end
147
+ end
148
+ end
149
+
150
+ def define_publish_task
151
+ desc "Upload document and HTML to rubyforge."
152
+ task :publish => ["html:publish", "reference:publish"]
153
+ end
154
+
155
+ def define_upload_tasks
156
+ namespace :rubyforge do
157
+ desc "Upload tar.gz to RubyForge."
158
+ task :upload => "package" do
159
+ print "password:"
160
+ system("stty -echo")
161
+ @rubyforge.userconfig["password"] = STDIN.gets.chomp
162
+ system("stty echo")
163
+ @rubyforge.add_release(@spec.rubyforge_project,
164
+ @spec.name,
165
+ @spec.version.to_s,
166
+ "pkg/#{@spec.name}-#{@spec.version}.tar.gz")
167
+ end
168
+ end
169
+ desc "Release to RubyForge."
170
+ task :rubyforge => "release:rubyforge:upload"
171
+ end
172
+
173
+ def rsync_to_rubyforge(spec, source, destination, options={})
174
+ host = "#{@rubyforge.userconfig["username"]}@rubyforge.org"
175
+
176
+ rsync_args = "-av --dry-run --exclude '*.erb' --chmod=ug+w"
177
+ rsync_args << " --delete" if options[:delete]
178
+ remote_dir = "/var/www/gforge-projects/#{spec.rubyforge_project}/"
179
+ sh("rsync #{rsync_args} #{source} #{host}:#{remote_dir}#{destination}")
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 yoshihara haruka <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ module Packnga
19
+ # Packnga version.
20
+ VERSION = "0.9.0"
21
+ end
@@ -0,0 +1,125 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2011 yoshihara haruka <yoshihara@clear-code.com>
4
+ # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License version 2.1 as published by the Free Software Foundation.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+
19
+ require "yard"
20
+
21
+ module Packnga
22
+ # This class creates YARD task.
23
+ # YARD task generate references by YARD.
24
+ #
25
+ # @since 0.9.0
26
+ class YARDTask
27
+ include Rake::DSL
28
+
29
+ attr_writer :readme
30
+ # This attribute is path of base directory of document.
31
+ attr_accessor :base_dir
32
+
33
+ # @private
34
+ def initialize(spec)
35
+ @spec = spec
36
+ @hooks = []
37
+ @readme = nil
38
+ @text_files = nil
39
+ @base_dir = nil
40
+ @files = spec.files.find_all do |file|
41
+ /\.rb\z/ =~ file
42
+ end
43
+ if block_given?
44
+ yield(self)
45
+ define
46
+ end
47
+ end
48
+
49
+ # This attribute is used to sets README file to yardoc task.
50
+ # @return [String] path to readme file
51
+ def readme
52
+ @readme || Rake::FileList["README*"].to_a.first
53
+ end
54
+
55
+ # @private
56
+ def text_files
57
+ @text_files ||= []
58
+ end
59
+
60
+ # @private
61
+ def define
62
+ set_default_values
63
+ define_tasks
64
+ end
65
+
66
+ # Regists yardoc parameters with block.
67
+ def before_define(&hook)
68
+ @hooks << hook
69
+ end
70
+
71
+ private
72
+ def set_default_values
73
+ @base_dir ||= "doc"
74
+ @base_dir = Pathname.new(@base_dir)
75
+ if @text_files.nil?
76
+ text_dir = @base_dir + "text"
77
+ @text_files = [(text_dir + "**/*").to_s] if text_dir.directory?
78
+ end
79
+ end
80
+
81
+ def reference_dir
82
+ @base_dir + "reference"
83
+ end
84
+
85
+ def reference_en_dir
86
+ reference_dir + "en"
87
+ end
88
+
89
+ def define_tasks
90
+ define_yardoc_task
91
+ define_yard_task
92
+ end
93
+
94
+ def define_yardoc_task
95
+ YARD::Rake::YardocTask.new do |yardoc_task|
96
+ yardoc_task.options += ["--title", @spec.name]
97
+ yardoc_task.options += ["--readme", readme]
98
+ @text_files.each do |file|
99
+ yardoc_task.options += ["--files", file]
100
+ end
101
+ yardoc_task.options += ["--output-dir", reference_en_dir.to_s]
102
+ yardoc_task.options += ["--charset", "utf-8"]
103
+ yardoc_task.options += ["--no-private"]
104
+ yardoc_task.files += @files
105
+ @hooks.each do |hook|
106
+ hook.call(yardoc_task)
107
+ end
108
+ end
109
+ end
110
+
111
+ def define_yard_task
112
+ task :yard do |yard_task|
113
+ reference_en_dir.find do |path|
114
+ next if path.extname != ".html"
115
+ html = path.read
116
+ html = html.gsub(/<div id="footer">.+<\/div>/m,
117
+ "<div id=\"footer\"></div>")
118
+ path.open("w") do |html_file|
119
+ html_file.print(html)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packnga
3
+ version: !ruby/object:Gem::Version
4
+ hash: 59
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
+ platform: ruby
12
+ authors:
13
+ - Haruka Yoshihara
14
+ - Kouhei Sutou
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-08-19 00:00:00 +09:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :runtime
24
+ prerelease: false
25
+ name: rubyforge
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 3
32
+ segments:
33
+ - 0
34
+ version: "0"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ prerelease: false
39
+ name: test-unit
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ prerelease: false
53
+ name: test-unit-notify
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ type: :development
66
+ prerelease: false
67
+ name: rake
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirement: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ type: :development
80
+ prerelease: false
81
+ name: jeweler
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirement: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ type: :development
94
+ prerelease: false
95
+ name: yard
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirement: *id006
106
+ description: |
107
+ Packnga is an library to translate to many languages by YARD.
108
+
109
+ email:
110
+ - yoshihara@clear-code.com
111
+ - kou@clear-code.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files:
117
+ - README.textile
118
+ files:
119
+ - Gemfile
120
+ - README.textile
121
+ - Rakefile
122
+ - doc/text/lgpl.txt
123
+ - doc/text/news.textile
124
+ - doc/text/tutorial.textile
125
+ - lib/packnga.rb
126
+ - lib/packnga/document-task.rb
127
+ - lib/packnga/reference-task.rb
128
+ - lib/packnga/release-task.rb
129
+ - lib/packnga/version.rb
130
+ - lib/packnga/yard-task.rb
131
+ has_rdoc: true
132
+ homepage: http://groonga.rubyforge.org/
133
+ licenses:
134
+ - LGPLv2
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project: groonga
161
+ rubygems_version: 1.3.7
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: An utility library to package i18n-ed library.
165
+ test_files: []
166
+