to_activerecord 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2007-06-16
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Dr Nic Williams
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,18 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/to_activerecord.rb
7
+ lib/to_activerecord/fixnum.rb
8
+ lib/to_activerecord/version.rb
9
+ scripts/txt2html
10
+ setup.rb
11
+ test/test_helper.rb
12
+ test/test_to_activerecord.rb
13
+ website/index.html
14
+ website/index.txt
15
+ website/javascripts/rounded_corners_lite.inc.js
16
+ website/presentation.yaml
17
+ website/stylesheets/screen.css
18
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1 @@
1
+ See http://drnicwilliams.rubyforge.org/to_activerecord
data/Rakefile ADDED
@@ -0,0 +1,129 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+
12
+ include FileUtils
13
+ require File.join(File.dirname(__FILE__), 'lib', 'to_activerecord', 'version')
14
+
15
+ AUTHOR = 'Dr Nic Williams' # can also be an array of Authors
16
+ EMAIL = "drnicwilliams@gmail.com"
17
+ DESCRIPTION = <<-EOS
18
+ Find ActiveRecord instances via their ID value.
19
+
20
+ Now you can use 37.to_post instead of Post.find(37).
21
+
22
+ Used in conjunction with the map_by_method gem: [37,103].map_by_to_post
23
+ EOS
24
+ GEM_NAME = 'to_activerecord' # what ppl will type to install your gem
25
+
26
+ @config_file = "~/.rubyforge/user-config.yml"
27
+ @config = nil
28
+ def rubyforge_username
29
+ unless @config
30
+ begin
31
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
32
+ rescue
33
+ puts <<-EOS
34
+ ERROR: No rubyforge config file found: #{@config_file}"
35
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
36
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
37
+ EOS
38
+ exit
39
+ end
40
+ end
41
+ @rubyforge_username ||= @config["username"]
42
+ end
43
+
44
+ RUBYFORGE_PROJECT = 'drnicutilities' # The unix name for your project
45
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
46
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
47
+
48
+ NAME = "to_activerecord"
49
+ REV = nil
50
+ # UNCOMMENT IF REQUIRED:
51
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
52
+ VERS = ToActiverecord::VERSION::STRING + (REV ? ".#{REV}" : "")
53
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
54
+ RDOC_OPTS = ['--quiet', '--title', 'to_activerecord documentation',
55
+ "--opname", "index.html",
56
+ "--line-numbers",
57
+ "--main", "README",
58
+ "--inline-source"]
59
+
60
+ class Hoe
61
+ def extra_deps
62
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
63
+ end
64
+ end
65
+
66
+ # Generate all the Rake tasks
67
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
68
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
69
+ p.author = AUTHOR
70
+ p.description = DESCRIPTION
71
+ p.email = EMAIL
72
+ p.summary = DESCRIPTION
73
+ p.url = HOMEPATH
74
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
75
+ p.test_globs = ["test/**/test_*.rb"]
76
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
77
+
78
+ # == Optional
79
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
80
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
81
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
82
+ end
83
+
84
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
85
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
86
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
87
+
88
+ desc 'Generate website files'
89
+ task :website_generate do
90
+ Dir['website/**/*.txt'].each do |txt|
91
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
92
+ end
93
+ end
94
+
95
+ desc 'Upload website files to rubyforge'
96
+ task :website_upload do
97
+ host = "#{rubyforge_username}@rubyforge.org"
98
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
99
+ local_dir = 'website'
100
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
101
+ end
102
+
103
+ desc 'Generate and upload website files'
104
+ task :website => [:website_generate, :website_upload, :publish_docs]
105
+
106
+ desc 'Release the website and new gem version'
107
+ task :deploy => [:check_version, :website, :release] do
108
+ puts "Remember to create SVN tag:"
109
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
110
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
111
+ puts "Suggested comment:"
112
+ puts "Tagging release #{CHANGES}"
113
+ end
114
+
115
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
116
+ task :local_deploy => [:website_generate, :install_gem]
117
+
118
+ task :check_version do
119
+ unless ENV['VERSION']
120
+ puts 'Must pass a VERSION=x.y.z release version'
121
+ exit
122
+ end
123
+ unless ENV['VERSION'] == VERS
124
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
125
+ exit
126
+ end
127
+ end
128
+
129
+
@@ -0,0 +1,15 @@
1
+ module ToActiveRecord
2
+ module Fixnum
3
+ module ClassMethods
4
+
5
+ end
6
+
7
+ extend ClassMethods
8
+
9
+ def self.included(receiver)
10
+ receiver.extend(ClassMethods)
11
+ end
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module ToActiverecord #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module ToActiverecord
2
+ end
3
+
4
+ require 'to_activerecord/version'
5
+
6
+ begin
7
+ require 'active_support'
8
+ rescue
9
+ require 'rubygems'
10
+ require 'active_support'
11
+ end
12
+
13
+ # Fixnum.send(:include, ToActiverecord::Fixnum)
14
+
15
+ class Fixnum
16
+ def method_missing(meth, *args, &block)
17
+ pattern = /^to_([a-z][a-z_]*)$/
18
+ if match = pattern.match(meth.to_s)
19
+ if match_class = match[1].capitalize.constantize rescue nil
20
+ return match_class.send(:find, *([self] + args), &block)
21
+ end
22
+ end
23
+ super
24
+ end
25
+ end
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/to_activerecord/version.rb'
8
+
9
+ version = ToActiverecord::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/to_activerecord'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)