ciuchcia 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +0 -0
- data/Manifest.txt +26 -0
- data/README.txt +41 -0
- data/Rakefile +23 -0
- data/lib/ciuchcia/date.rb +12 -0
- data/lib/ciuchcia/distance_of_time.rb +49 -0
- data/lib/ciuchcia/error_messages_for.rb +39 -0
- data/lib/ciuchcia/number_in_words.rb +43 -0
- data/lib/ciuchcia/validations.rb +76 -0
- data/lib/ciuchcia.rb +56 -0
- data/spec/ciuchcia_spec.rb +36 -0
- data/spec/spec_helper.rb +17 -0
- data/tasks/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +126 -0
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +49 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +268 -0
- data/tasks/spec.rake +55 -0
- data/tasks/svn.rake +48 -0
- data/tasks/test.rake +38 -0
- data/test/test_ciuchcia.rb +0 -0
- metadata +89 -0
data/History.txt
ADDED
File without changes
|
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
lib/ciuchcia.rb
|
6
|
+
lib/ciuchcia/date.rb
|
7
|
+
lib/ciuchcia/distance_of_time.rb
|
8
|
+
lib/ciuchcia/error_messages_for.rb
|
9
|
+
lib/ciuchcia/number_in_words.rb
|
10
|
+
lib/ciuchcia/validations.rb
|
11
|
+
spec/ciuchcia_spec.rb
|
12
|
+
spec/spec_helper.rb
|
13
|
+
tasks/ann.rake
|
14
|
+
tasks/bones.rake
|
15
|
+
tasks/gem.rake
|
16
|
+
tasks/git.rake
|
17
|
+
tasks/manifest.rake
|
18
|
+
tasks/notes.rake
|
19
|
+
tasks/post_load.rake
|
20
|
+
tasks/rdoc.rake
|
21
|
+
tasks/rubyforge.rake
|
22
|
+
tasks/setup.rb
|
23
|
+
tasks/spec.rake
|
24
|
+
tasks/svn.rake
|
25
|
+
tasks/test.rake
|
26
|
+
test/test_ciuchcia.rb
|
data/README.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
ciuchcia
|
2
|
+
by Kacper Cieśla
|
3
|
+
http://ciuchcia.rubyforge.org/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Library for rails apps polonization.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
http://ciuchcia.rubyforge.org/
|
11
|
+
== SYNOPSIS:
|
12
|
+
http://ciuchcia.rubyforge.org/
|
13
|
+
== REQUIREMENTS:
|
14
|
+
http://ciuchcia.rubyforge.org/
|
15
|
+
== INSTALL:
|
16
|
+
http://ciuchcia.rubyforge.org/
|
17
|
+
|
18
|
+
== LICENSE:
|
19
|
+
|
20
|
+
(The MIT License)
|
21
|
+
|
22
|
+
Copyright (c) 2008 FIXME (different license?)
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
25
|
+
a copy of this software and associated documentation files (the
|
26
|
+
'Software'), to deal in the Software without restriction, including
|
27
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
28
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
29
|
+
permit persons to whom the Software is furnished to do so, subject to
|
30
|
+
the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be
|
33
|
+
included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
36
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
37
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
38
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
39
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
40
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
41
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
load 'tasks/setup.rb'
|
6
|
+
|
7
|
+
ensure_in_path 'lib'
|
8
|
+
require 'ciuchcia'
|
9
|
+
|
10
|
+
task :default => 'spec:run'
|
11
|
+
|
12
|
+
PROJ.name = 'ciuchcia'
|
13
|
+
PROJ.version = '0.0.1'
|
14
|
+
PROJ.authors = 'Kacper Cieśla'
|
15
|
+
PROJ.email = 'kacper.ciesla@gmail.com'
|
16
|
+
PROJ.url = 'FIXME (project homepage)'
|
17
|
+
PROJ.rubyforge.name = 'ciuchcia'
|
18
|
+
|
19
|
+
PROJ.spec.opts << '--color'
|
20
|
+
|
21
|
+
depend_on 'rails'
|
22
|
+
|
23
|
+
# EOF
|
@@ -0,0 +1,12 @@
|
|
1
|
+
if Object.const_defined? 'Date'
|
2
|
+
|
3
|
+
class CiuchciaDate < Date
|
4
|
+
MONTHNAMES = [nil] + %w{Styczeń Luty Marzec Kwiecień Maj Czerwiec Lipiec Sierpień Wrzesień Październik Listopad Grudzień}
|
5
|
+
DAYNAMES = ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"]
|
6
|
+
end
|
7
|
+
|
8
|
+
# This generates warning, that's definitely bad
|
9
|
+
# If you know how to avoid it, please let me know
|
10
|
+
Date = CiuchciaDate
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module DateHelper
|
4
|
+
|
5
|
+
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
|
6
|
+
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
7
|
+
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
8
|
+
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
9
|
+
distance_in_seconds = ((to_time - from_time).abs).round
|
10
|
+
|
11
|
+
def polish_ending(n, endings)
|
12
|
+
case (n % 10)
|
13
|
+
when 1: n > 10 ? endings[2] : endings[0]
|
14
|
+
when 2..4: endings[1]
|
15
|
+
else endings[2]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
case distance_in_minutes
|
20
|
+
when 0..1
|
21
|
+
return (distance_in_minutes == 0) ? 'mniej niż minuta' : '1 minuta' unless include_seconds
|
22
|
+
case distance_in_seconds
|
23
|
+
when 0..4 then 'mniej niż 5 sekund'
|
24
|
+
when 5..9 then 'mniej niż 10 sekund'
|
25
|
+
when 10..19 then 'mniej niż dwadzieścias sekund'
|
26
|
+
when 20..39 then 'pół minuty'
|
27
|
+
when 40..59 then 'niecała minuta'
|
28
|
+
else '1 minuta'
|
29
|
+
end
|
30
|
+
|
31
|
+
when 2..44 then "#{distance_in_minutes} #{polish_ending(distance_in_minutes,['minuta','minuty','minut'])}"
|
32
|
+
when 45..89 then 'około godzina'
|
33
|
+
when 90..1439 then "około #{(distance_in_minutes.to_f / 60.0).round} #{polish_ending((distance_in_minutes.to_f / 60.0).round,['godzina','godziny','godzin'])}"
|
34
|
+
when 1440..2879 then '1 dzień'
|
35
|
+
when 2880..43199 then "#{(distance_in_minutes / 1440).round} dni"
|
36
|
+
when 43200..86399 then 'około 1 miesiąc'
|
37
|
+
when 86400..525599 then "#{(distance_in_minutes / 43200).round} #{polish_ending((distance_in_minutes / 43200).round,['miesiąc','miesiące','miesięcy'])}"
|
38
|
+
when 525600..1051199 then 'około rok'
|
39
|
+
else "ponad #{(distance_in_minutes / 525600).round} #{polish_ending((distance_in_minutes / 525600).round,['rok','lata','lat'])}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def time_ago_in_words(from_time, include_seconds = false)
|
44
|
+
distance_of_time_in_words(from_time, Time.now, include_seconds)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Errors
|
3
|
+
def full_messages
|
4
|
+
full_messages = []
|
5
|
+
@errors.each_key do |attr|
|
6
|
+
@errors[attr].each do |msg|
|
7
|
+
next if msg.nil?
|
8
|
+
full_messages << msg
|
9
|
+
end
|
10
|
+
end
|
11
|
+
full_messages
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ActionView
|
17
|
+
module Helpers
|
18
|
+
module ActiveRecordHelper
|
19
|
+
|
20
|
+
def error_messages_for(object_name, options = {})
|
21
|
+
options = options.symbolize_keys
|
22
|
+
object = instance_variable_get("@#{object_name}")
|
23
|
+
unless object.errors.empty?
|
24
|
+
content_tag("div",
|
25
|
+
content_tag(
|
26
|
+
options[:header_tag] || "h2",
|
27
|
+
# We could put here error numbers, you can use object.errors.count
|
28
|
+
"Formularz nie został wysłany ponieważ zawiera błędy"
|
29
|
+
) +
|
30
|
+
content_tag("p", "Wystąpiły następujące problemy:") +
|
31
|
+
content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }),
|
32
|
+
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#module Ciuchcia
|
2
|
+
#class << self
|
3
|
+
|
4
|
+
# Number in words
|
5
|
+
# Example usage:
|
6
|
+
# number_in_words(107) # returns "sto siedem"
|
7
|
+
def number_in_words(n,ending=nil)
|
8
|
+
# It's probably the worst code in ruby I've ever written
|
9
|
+
# It seems to work, but it definitely should not ;)
|
10
|
+
return '' if n == 0
|
11
|
+
sc = [''] + %w{jeden dwa trzy cztery pięć sześć siedem osiem dziewięć}
|
12
|
+
sn = %w{dziesięć jedenaście dwanaście trzynaście czternaście piętnaście szesnaście siedemnaście osiemnaście dziewiętnaście}
|
13
|
+
sd = ['',''] + %w{dwadzieścia trzydzieści czterdzieści pięćdziesiąt sześćdziesiąt siedemdziesiąt osiemdziesiąt dziewiędziesiąt sto}
|
14
|
+
ss = [''] + %w{sto dwieście trzysta czterysta pięćset sześćset siedemset osiemset dziewięćset}
|
15
|
+
b = (ending || ['','','']),%w{tysiąc tysiące tysięcy},%w{milion miliony milionów},%w{miliard miliardy miliarðów}
|
16
|
+
p = n.to_s.size
|
17
|
+
return 'bardzo dużo' if p > 11
|
18
|
+
d,dn = n.to_s[0,(p%3 == 0 ? 3 : p%3)], n.to_s[(p%3 == 0 ? 3 : p%3)..-1]
|
19
|
+
return "#{d.to_i==0 ? '' : b[((p-1)/3.0).floor][0]} #{number_in_words(dn,ending)}".strip if (d.to_i == 1 or d.to_i == 0 ) and n != 1
|
20
|
+
r = ''
|
21
|
+
(d.size-1).downto(0) do |i|
|
22
|
+
r += ' ' unless r[-1] and r[-1].chr == ' '
|
23
|
+
r += ss[d[-i-1].chr.to_i] if i == 2
|
24
|
+
d[-i-1].chr.to_i == 1 ? (r += sn[d[-i].chr.to_i]; d = d[0..-2]; break) : r += sd[d[-i-1].chr.to_i] if i == 1
|
25
|
+
r += sc[d[-i-1].chr.to_i] if i == 0
|
26
|
+
end
|
27
|
+
(2..4) === (d.to_i % 10) ? k=1 : k=2
|
28
|
+
"#{r.strip} #{b[((p-1)/3.0).floor][k]} #{number_in_words(dn.to_i,ending)}".strip
|
29
|
+
end
|
30
|
+
|
31
|
+
# Money in words
|
32
|
+
# Same as number in words but adds currency name
|
33
|
+
# money_in_words (2.50) # "dwa złote pięćdziesiąt groszy
|
34
|
+
def money_in_words(x)
|
35
|
+
zl = x.floor; gr = (x*100).round%100; r = ''
|
36
|
+
r += number_in_words(zl,['złoty','złote','złotych']) if zl > 0
|
37
|
+
r += ' '+number_in_words(gr,['grosz','grosze','groszy']) if gr > 0
|
38
|
+
r
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#end
|
43
|
+
#end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Ciuchcia
|
2
|
+
class Validations
|
3
|
+
|
4
|
+
def self.valid_nip?(nip)
|
5
|
+
# validates presence
|
6
|
+
return false if nip.nil? or (nip.empty? rescue true)
|
7
|
+
|
8
|
+
# format (should be 10 digits)
|
9
|
+
nip.gsub!(/\ |\-|\../,'')
|
10
|
+
return false unless nip.match(/^\d{10}$/)
|
11
|
+
|
12
|
+
# control digit value
|
13
|
+
weights = [6,5,7,2,3,4,5,6,7]
|
14
|
+
digits = nip.split('').map {|i| i.to_i }
|
15
|
+
return false unless digits[-1] == digits[0..-2].inject(0) { |sum,x| sum + x*weights.shift } % 11 % 10
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.valid_regon?(regon)
|
20
|
+
# validates presence
|
21
|
+
return false if regon.nil? or (regon.empty? rescue true)
|
22
|
+
|
23
|
+
# format (should be 10 digits)
|
24
|
+
regon.gsub!(/\ |\-|\../,'')
|
25
|
+
|
26
|
+
if regon.size == 14
|
27
|
+
# long regon
|
28
|
+
long_regon = regon
|
29
|
+
regon = regon[0..8]
|
30
|
+
end
|
31
|
+
return false unless regon.match(/^\d{9}$/)
|
32
|
+
|
33
|
+
# control digit value
|
34
|
+
weights = [8,9,2,3,4,5,6,7]
|
35
|
+
digits = regon.split('').map {|i| i.to_i }
|
36
|
+
return false unless digits[-1] == digits[0..-2].inject(0) { |sum,x| sum + x*weights.shift } % 11 % 10
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module ActiveRecord
|
44
|
+
class Base
|
45
|
+
class << self
|
46
|
+
|
47
|
+
def validates_nip(*attr_names)
|
48
|
+
configuration = { :message => 'Niepoprawny numer NIP', :on => :save }
|
49
|
+
configuration.update(attr_names.extract_options!)
|
50
|
+
|
51
|
+
attr_accessor(*(attr_names.map { |n| "#{n}_confirmation" }))
|
52
|
+
|
53
|
+
validates_each(attr_names, configuration) do |record, attr_name, value|
|
54
|
+
value = record.send("#{attr_name}")
|
55
|
+
record.errors.add(attr_name, configuration[:message]) unless Ciuchcia::Validations.valid_nip? value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def validates_regon(*attr_names)
|
60
|
+
configuration = { :message => 'Niepoprawny numer REGON', :on => :save }
|
61
|
+
configuration.update(attr_names.extract_options!)
|
62
|
+
|
63
|
+
attr_accessor(*(attr_names.map { |n| "#{n}_confirmation" }))
|
64
|
+
|
65
|
+
validates_each(attr_names, configuration) do |record, attr_name, value|
|
66
|
+
value = record.send("#{attr_name}")
|
67
|
+
record.errors.add(attr_name, configuration[:message]) unless Ciuchcia::Validationsvalid_regon? value
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/lib/ciuchcia.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
# Equivalent to a header guard in C/C++
|
4
|
+
# Used to prevent the class/module from being loaded more than once
|
5
|
+
unless defined? Ciuchcia
|
6
|
+
|
7
|
+
module Ciuchcia
|
8
|
+
|
9
|
+
# :stopdoc:
|
10
|
+
VERSION = '0.0.1'
|
11
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
12
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
13
|
+
# :startdoc:
|
14
|
+
|
15
|
+
# Returns the version string for the library.
|
16
|
+
#
|
17
|
+
def self.version
|
18
|
+
VERSION
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the library path for the module. If any arguments are given,
|
22
|
+
# they will be joined to the end of the libray path using
|
23
|
+
# <tt>File.join</tt>.
|
24
|
+
#
|
25
|
+
def self.libpath( *args )
|
26
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns the lpath for the module. If any arguments are given,
|
30
|
+
# they will be joined to the end of the path using
|
31
|
+
# <tt>File.join</tt>.
|
32
|
+
#
|
33
|
+
def self.path( *args )
|
34
|
+
args.empty? ? PATH : ::File.join(PATH, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Utility method used to rquire all files ending in .rb that lie in the
|
38
|
+
# directory below this file that has the same name as the filename passed
|
39
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
40
|
+
# the _filename_ does not have to be equivalent to the directory.
|
41
|
+
#
|
42
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
43
|
+
dir ||= ::File.basename(fname, '.*')
|
44
|
+
search_me = ::File.expand_path(
|
45
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
46
|
+
|
47
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
48
|
+
end
|
49
|
+
|
50
|
+
end # module Ciuchcia
|
51
|
+
|
52
|
+
Ciuchcia.require_all_libs_relative_to __FILE__
|
53
|
+
|
54
|
+
end # unless defined?
|
55
|
+
|
56
|
+
# EOF
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
4
|
+
|
5
|
+
describe Ciuchcia do
|
6
|
+
it "should correctly tralnlate numbers to words" do
|
7
|
+
number_in_words(123).should eql("sto dwadzieścia trzy")
|
8
|
+
number_in_words(1047).should eql("tysiąc czterdzieści siedem")
|
9
|
+
number_in_words(12).should eql("dwanaście")
|
10
|
+
number_in_words(666).should eql("sześćset sześćdziesiąt sześć")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should know how to count mouney" do
|
14
|
+
money_in_words(13.45).should eql("trzynaście złotych czterdzieści pięć groszy")
|
15
|
+
money_in_words(2.30).should eql("dwa złote trzydzieści groszy")
|
16
|
+
money_in_words(2401).should eql("dwa tysiące czterysta jeden złotych")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should correctly validates NIP number" do
|
20
|
+
ActiveRecord::Base.valid_nip?('779-21-25-257').should == true
|
21
|
+
ActiveRecord::Base.valid_nip?('779-21-25-254').should == false
|
22
|
+
ActiveRecord::Base.valid_nip?('blablabla').should == false
|
23
|
+
ActiveRecord::Base.valid_nip?('blablabla').should == false
|
24
|
+
ActiveRecord::Base.valid_nip?('779-21-25-25423').should == false
|
25
|
+
ActiveRecord::Base.valid_nip?('7792125223').should == false
|
26
|
+
ActiveRecord::Base.valid_nip?('525-21-85-036').should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should correctly validates REGON number" do
|
30
|
+
ActiveRecord::Base.valid_regon?('016385358').should == true
|
31
|
+
ActiveRecord::Base.valid_nip?('016385354').should == false
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. lib ciuchcia]))
|
5
|
+
|
6
|
+
Spec::Runner.configure do |config|
|
7
|
+
# == Mock Framework
|
8
|
+
#
|
9
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
10
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
11
|
+
#
|
12
|
+
# config.mock_with :mocha
|
13
|
+
# config.mock_with :flexmock
|
14
|
+
# config.mock_with :rr
|
15
|
+
end
|
16
|
+
|
17
|
+
# EOF
|
data/tasks/ann.rake
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bones/smtp_tls'
|
5
|
+
rescue LoadError
|
6
|
+
require 'net/smtp'
|
7
|
+
end
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
namespace :ann do
|
11
|
+
|
12
|
+
# A prerequisites task that all other tasks depend upon
|
13
|
+
task :prereqs
|
14
|
+
|
15
|
+
file PROJ.ann.file do
|
16
|
+
ann = PROJ.ann
|
17
|
+
puts "Generating #{ann.file}"
|
18
|
+
File.open(ann.file,'w') do |fd|
|
19
|
+
fd.puts("#{PROJ.name} version #{PROJ.version}")
|
20
|
+
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
|
21
|
+
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
|
22
|
+
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
|
23
|
+
fd.puts
|
24
|
+
fd.puts("== DESCRIPTION")
|
25
|
+
fd.puts
|
26
|
+
fd.puts(PROJ.description)
|
27
|
+
fd.puts
|
28
|
+
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
|
29
|
+
fd.puts
|
30
|
+
ann.paragraphs.each do |p|
|
31
|
+
fd.puts "== #{p.upcase}"
|
32
|
+
fd.puts
|
33
|
+
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
|
34
|
+
fd.puts
|
35
|
+
end
|
36
|
+
fd.puts ann.text if ann.text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Create an announcement file"
|
41
|
+
task :announcement => ['ann:prereqs', PROJ.ann.file]
|
42
|
+
|
43
|
+
desc "Send an email announcement"
|
44
|
+
task :email => ['ann:prereqs', PROJ.ann.file] do
|
45
|
+
ann = PROJ.ann
|
46
|
+
from = ann.email[:from] || PROJ.email
|
47
|
+
to = Array(ann.email[:to])
|
48
|
+
|
49
|
+
### build a mail header for RFC 822
|
50
|
+
rfc822msg = "From: #{from}\n"
|
51
|
+
rfc822msg << "To: #{to.join(',')}\n"
|
52
|
+
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
|
53
|
+
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
|
54
|
+
rfc822msg << "\n"
|
55
|
+
rfc822msg << "Date: #{Time.new.rfc822}\n"
|
56
|
+
rfc822msg << "Message-Id: "
|
57
|
+
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
|
58
|
+
rfc822msg << File.read(ann.file)
|
59
|
+
|
60
|
+
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
|
61
|
+
ann.email[key]
|
62
|
+
end
|
63
|
+
|
64
|
+
params[3] = PROJ.email if params[3].nil?
|
65
|
+
|
66
|
+
if params[4].nil?
|
67
|
+
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
|
68
|
+
params[4] = STDIN.gets.chomp
|
69
|
+
end
|
70
|
+
|
71
|
+
### send email
|
72
|
+
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
|
73
|
+
end
|
74
|
+
end # namespace :ann
|
75
|
+
|
76
|
+
desc 'Alias to ann:announcement'
|
77
|
+
task :ann => 'ann:announcement'
|
78
|
+
|
79
|
+
CLOBBER << PROJ.ann.file
|
80
|
+
|
81
|
+
# EOF
|
data/tasks/bones.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_BONES
|
4
|
+
|
5
|
+
namespace :bones do
|
6
|
+
|
7
|
+
desc 'Show the PROJ open struct'
|
8
|
+
task :debug do |t|
|
9
|
+
atr = if t.application.top_level_tasks.length == 2
|
10
|
+
t.application.top_level_tasks.pop
|
11
|
+
end
|
12
|
+
|
13
|
+
if atr then Bones::Debug.show_attr(PROJ, atr)
|
14
|
+
else Bones::Debug.show PROJ end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # namespace :bones
|
18
|
+
|
19
|
+
end # HAVE_BONES
|
20
|
+
|
21
|
+
# EOF
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
namespace :gem do
|
6
|
+
|
7
|
+
PROJ.gem._spec = Gem::Specification.new do |s|
|
8
|
+
s.name = PROJ.name
|
9
|
+
s.version = PROJ.version
|
10
|
+
s.summary = PROJ.summary
|
11
|
+
s.authors = Array(PROJ.authors)
|
12
|
+
s.email = PROJ.email
|
13
|
+
s.homepage = Array(PROJ.url).first
|
14
|
+
s.rubyforge_project = PROJ.rubyforge.name
|
15
|
+
|
16
|
+
s.description = PROJ.description
|
17
|
+
|
18
|
+
PROJ.gem.dependencies.each do |dep|
|
19
|
+
s.add_dependency(*dep)
|
20
|
+
end
|
21
|
+
|
22
|
+
s.files = PROJ.gem.files
|
23
|
+
s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
|
24
|
+
s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
|
25
|
+
|
26
|
+
s.bindir = 'bin'
|
27
|
+
dirs = Dir["{#{PROJ.libs.join(',')}}"]
|
28
|
+
s.require_paths = dirs unless dirs.empty?
|
29
|
+
|
30
|
+
incl = Regexp.new(PROJ.rdoc.include.join('|'))
|
31
|
+
excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
|
32
|
+
excl = Regexp.new(excl.join('|'))
|
33
|
+
rdoc_files = PROJ.gem.files.find_all do |fn|
|
34
|
+
case fn
|
35
|
+
when excl; false
|
36
|
+
when incl; true
|
37
|
+
else false end
|
38
|
+
end
|
39
|
+
s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
|
40
|
+
s.extra_rdoc_files = rdoc_files
|
41
|
+
s.has_rdoc = true
|
42
|
+
|
43
|
+
if test ?f, PROJ.test.file
|
44
|
+
s.test_file = PROJ.test.file
|
45
|
+
else
|
46
|
+
s.test_files = PROJ.test.files.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
# Do any extra stuff the user wants
|
50
|
+
PROJ.gem.extras.each do |msg, val|
|
51
|
+
case val
|
52
|
+
when Proc
|
53
|
+
val.call(s.send(msg))
|
54
|
+
else
|
55
|
+
s.send "#{msg}=", val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # Gem::Specification.new
|
59
|
+
|
60
|
+
# A prerequisites task that all other tasks depend upon
|
61
|
+
task :prereqs
|
62
|
+
|
63
|
+
desc 'Show information about the gem'
|
64
|
+
task :debug => 'gem:prereqs' do
|
65
|
+
puts PROJ.gem._spec.to_ruby
|
66
|
+
end
|
67
|
+
|
68
|
+
pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
|
69
|
+
pkg.need_tar = PROJ.gem.need_tar
|
70
|
+
pkg.need_zip = PROJ.gem.need_zip
|
71
|
+
pkg.package_files += PROJ.gem._spec.files
|
72
|
+
end
|
73
|
+
Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
|
74
|
+
|
75
|
+
gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
|
76
|
+
"#{pkg.package_name}.gem"
|
77
|
+
else
|
78
|
+
"#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Build the gem file #{gem_file}"
|
82
|
+
task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
|
83
|
+
|
84
|
+
file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
|
85
|
+
when_writing("Creating GEM") {
|
86
|
+
Gem::Builder.new(PROJ.gem._spec).build
|
87
|
+
verbose(true) {
|
88
|
+
mv gem_file, "#{pkg.package_dir}/#{gem_file}"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'Install the gem'
|
94
|
+
task :install => [:clobber, 'gem:package'] do
|
95
|
+
sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
|
96
|
+
|
97
|
+
# use this version of the command for rubygems > 1.0.0
|
98
|
+
#sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'Uninstall the gem'
|
102
|
+
task :uninstall do
|
103
|
+
installed_list = Gem.source_index.find_name(PROJ.name)
|
104
|
+
if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
|
105
|
+
sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
desc 'Reinstall the gem'
|
110
|
+
task :reinstall => [:uninstall, :install]
|
111
|
+
|
112
|
+
desc 'Cleanup the gem'
|
113
|
+
task :cleanup do
|
114
|
+
sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
|
115
|
+
end
|
116
|
+
|
117
|
+
end # namespace :gem
|
118
|
+
|
119
|
+
desc 'Alias to gem:package'
|
120
|
+
task :gem => 'gem:package'
|
121
|
+
|
122
|
+
task :clobber => 'gem:clobber_package'
|
123
|
+
|
124
|
+
remove_desc_for_task %w(gem:clobber_package)
|
125
|
+
|
126
|
+
# EOF
|