acts_as_markdown 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/LICENSE.txt +22 -0
- data/Manifest.txt +20 -0
- data/README.rdoc +50 -0
- data/Rakefile +23 -0
- data/acts_as_markdown.gemspec +30 -0
- data/lib/acts/as_markdown.rb +47 -0
- data/lib/acts_as_markdown/exts/rdiscount.rb +5 -0
- data/lib/acts_as_markdown.rb +60 -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/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/test.rake +34 -0
- data/test/acts_as_markdown_test.rb +95 -0
- data/test/test_helper.rb +21 -0
- metadata +74 -0
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2008 Brian Landau of Viget Labs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
acts_as_markdown.gemspec
|
7
|
+
lib/acts/as_markdown.rb
|
8
|
+
lib/acts_as_markdown.rb
|
9
|
+
lib/acts_as_markdown/exts/rdiscount.rb
|
10
|
+
tasks/bones.rake
|
11
|
+
tasks/gem.rake
|
12
|
+
tasks/git.rake
|
13
|
+
tasks/manifest.rake
|
14
|
+
tasks/post_load.rake
|
15
|
+
tasks/rdoc.rake
|
16
|
+
tasks/rubyforge.rake
|
17
|
+
tasks/setup.rb
|
18
|
+
tasks/test.rake
|
19
|
+
test/acts_as_markdown_test.rb
|
20
|
+
test/test_helper.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= acts_as_markdown
|
2
|
+
|
3
|
+
by Brian Landau of Viget Labs <brian.landau@viget.com>
|
4
|
+
|
5
|
+
GitHub Project: http://github.com/vigetlabs/acts_as_markdown
|
6
|
+
|
7
|
+
RDoc: http://viget.rubyforge.org/acts_as_markdown
|
8
|
+
|
9
|
+
|
10
|
+
== DESCRIPTION:
|
11
|
+
|
12
|
+
Allows you to specify columns of an ActiveRecord model that contain Markdown text.
|
13
|
+
You may then use +to_s+ to get the original markdown text or +to_html+ to get the
|
14
|
+
formated HTML.
|
15
|
+
|
16
|
+
This AR extension can use 3 different types of Markdown processing backends:
|
17
|
+
BlueCloth, RDiscount, or Ruby PEG. You specify which one you want to use by setting
|
18
|
+
a config value in your environment.rb file:
|
19
|
+
|
20
|
+
ActsAsMarkdown.markdown_library = :bluecloth
|
21
|
+
|
22
|
+
By default RDiscount will be used.
|
23
|
+
|
24
|
+
== EXAMPLE:
|
25
|
+
|
26
|
+
class Post < ActiveRecrod
|
27
|
+
acts_as_markdown :body
|
28
|
+
end
|
29
|
+
|
30
|
+
@post = Post.find(:first)
|
31
|
+
@post.body.to_s #=> "## Markdown Headline"
|
32
|
+
@post.body.to_html #=> "<h2> Mardown Headline</h2>"
|
33
|
+
|
34
|
+
== REQUIREMENTS:
|
35
|
+
|
36
|
+
You will also need to install some type of Markdown processor.
|
37
|
+
The three options currently supported are:
|
38
|
+
|
39
|
+
* BlueCloth
|
40
|
+
* RDiscount[http://github.com/rtomayko/rdiscount]
|
41
|
+
* {Ruby PEG}[http://github.com/rtomayko/rpeg-markdown/tree/master]
|
42
|
+
|
43
|
+
== INSTALL:
|
44
|
+
|
45
|
+
<tt>sudo gem install acts_as_markdown</tt>
|
46
|
+
|
47
|
+
Add "+acts_as_markdown+" to your environment.rb:
|
48
|
+
|
49
|
+
config.gem "acts_as_markdown"
|
50
|
+
|
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 'acts_as_markdown'
|
9
|
+
|
10
|
+
task :default => 'test:run'
|
11
|
+
|
12
|
+
PROJ.name = 'acts_as_markdown'
|
13
|
+
PROJ.authors = 'Brian Landau'
|
14
|
+
PROJ.email = 'brian.landau@viget.com'
|
15
|
+
PROJ.url = 'http://viget.rubyforge.com/acts_as_markdown'
|
16
|
+
PROJ.description = "Represent ActiveRecord markdown text columns as Markdown objects using various external libraries to convert to HTML."
|
17
|
+
PROJ.rubyforge.name = 'viget'
|
18
|
+
PROJ.dependencies = ['active_support', 'active_record']
|
19
|
+
PROJ.version = ActsAsMarkdown::VERSION
|
20
|
+
PROJ.rdoc.include = %w(^lib/ LICENSE\.txt README\.rdoc)
|
21
|
+
PROJ.rdoc.remote_dir = 'acts_as_markdown'
|
22
|
+
PROJ.test.files = FileList['test/**/*_test.rb']
|
23
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{acts_as_markdown}
|
3
|
+
s.version = "0.1.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Brian Landau"]
|
7
|
+
s.date = %q{2008-08-04}
|
8
|
+
s.description = %q{Represent ActiveRecord markdown text columns as Markdown objects using various external libraries to convert to HTML.}
|
9
|
+
s.email = %q{brian.landau@viget.com}
|
10
|
+
s.extra_rdoc_files = ["LICENSE.txt", "README.rdoc"]
|
11
|
+
s.files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.rdoc", "Rakefile", "acts_as_markdown.gemspec", "lib/acts/as_markdown.rb", "lib/acts_as_markdown.rb", "lib/acts_as_markdown/exts/rdiscount.rb", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/test.rake", "test/acts_as_markdown_test.rb", "test/test_helper.rb"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.homepage = %q{http://viget.rubyforge.com/acts_as_markdown}
|
14
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.rubyforge_project = %q{viget}
|
17
|
+
s.rubygems_version = %q{1.2.0}
|
18
|
+
s.summary = %q{Represent ActiveRecord markdown text columns as Markdown objects using various external libraries to convert to HTML}
|
19
|
+
s.test_files = ["test/acts_as_markdown_test.rb"]
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 2
|
24
|
+
|
25
|
+
if current_version >= 3 then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveRecord # :nodoc:
|
4
|
+
module Acts # :nodoc:
|
5
|
+
module AsMarkdown
|
6
|
+
def self.included(base) # :nodoc:
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
##
|
12
|
+
# This allows you to specify columns you want to define as containing markdown content.
|
13
|
+
# Then you can simply call +.to_html+ method on the attribute.
|
14
|
+
#
|
15
|
+
# === Example
|
16
|
+
# class Post < ActiveRecrod
|
17
|
+
# acts_as_markdown :body
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# @post = Post.find(:first)
|
21
|
+
# @post.body.to_s #=> "## Markdown Headline"
|
22
|
+
# @post.body.to_html #=> "<h2> Mardown Headline</h2>"
|
23
|
+
#
|
24
|
+
def acts_as_markdown(*columns)
|
25
|
+
library_names = ::ActsAsMarkdown::MARKDOWN_LIBS[ActsAsMarkdown.markdown_library]
|
26
|
+
require library_names[:lib_name]
|
27
|
+
klass = library_names[:class_name]
|
28
|
+
|
29
|
+
columns.each do |col|
|
30
|
+
class_eval <<-EOV
|
31
|
+
def #{col.to_s}
|
32
|
+
if @#{col.to_s}
|
33
|
+
if !self.#{col.to_s}_changed?
|
34
|
+
return @#{col.to_s}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@#{col.to_s} = #{klass}.new(self['#{col.to_s}'])
|
38
|
+
end
|
39
|
+
EOV
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
ActiveRecord::Base.send :include, ActiveRecord::Acts::AsMarkdown
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module ActsAsMarkdown
|
4
|
+
# :stopdoc:
|
5
|
+
VERSION = '0.1.0'
|
6
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
|
+
# :startdoc:
|
9
|
+
|
10
|
+
MARKDOWN_LIBS = { :rdiscount => {:class_name => "RDiscount",
|
11
|
+
:lib_name => "rdiscount"},
|
12
|
+
:bluecloth => {:class_name => "BlueCloth",
|
13
|
+
:lib_name => "bluecloth"},
|
14
|
+
:rpeg => {:class_name => "PEGMarkdown",
|
15
|
+
:lib_name => "peg_markdown"} }
|
16
|
+
|
17
|
+
@@markdown_library = :rdiscount
|
18
|
+
mattr_accessor :markdown_library
|
19
|
+
|
20
|
+
# :stopdoc:
|
21
|
+
# Returns the version string for the library.
|
22
|
+
#
|
23
|
+
def self.version
|
24
|
+
VERSION
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the library path for the module. If any arguments are given,
|
28
|
+
# they will be joined to the end of the libray path using
|
29
|
+
# <tt>File.join</tt>.
|
30
|
+
#
|
31
|
+
def self.libpath( *args )
|
32
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the lpath for the module. If any arguments are given,
|
36
|
+
# they will be joined to the end of the path using
|
37
|
+
# <tt>File.join</tt>.
|
38
|
+
#
|
39
|
+
def self.path( *args )
|
40
|
+
args.empty? ? PATH : ::File.join(PATH, *args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Utility method used to rquire all files ending in .rb that lie in the
|
44
|
+
# directory below this file that has the same name as the filename passed
|
45
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
46
|
+
# the _filename_ does not have to be equivalent to the directory.
|
47
|
+
#
|
48
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
49
|
+
dir ||= ::File.basename(fname, '.*')
|
50
|
+
search_me = ::File.expand_path(
|
51
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
52
|
+
|
53
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
54
|
+
end
|
55
|
+
# :startdoc:
|
56
|
+
|
57
|
+
end # module ActsAsMarkdown
|
58
|
+
|
59
|
+
ActsAsMarkdown.require_all_libs_relative_to __FILE__
|
60
|
+
ActsAsMarkdown.require_all_libs_relative_to __FILE__, 'acts'
|
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
|
data/tasks/git.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_GIT
|
4
|
+
|
5
|
+
namespace :git do
|
6
|
+
|
7
|
+
# A prerequisites task that all other tasks depend upon
|
8
|
+
task :prereqs
|
9
|
+
|
10
|
+
desc 'Show tags from the Git repository'
|
11
|
+
task :show_tags => 'git:prereqs' do |t|
|
12
|
+
puts %x/git tag/
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Create a new tag in the Git repository'
|
16
|
+
task :create_tag => 'git:prereqs' do |t|
|
17
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
18
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
19
|
+
|
20
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
21
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
22
|
+
|
23
|
+
puts "Creating Git tag '#{tag}'"
|
24
|
+
unless system "git tag -a -m '#{msg}' #{tag}"
|
25
|
+
abort "Tag creation failed"
|
26
|
+
end
|
27
|
+
|
28
|
+
if %x/git remote/ =~ %r/^origin\s*$/
|
29
|
+
unless system "git push origin #{tag}"
|
30
|
+
abort "Could not push tag to remote Git repository"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end # namespace :git
|
36
|
+
|
37
|
+
# task 'gem:release' => 'git:create_tag'
|
38
|
+
|
39
|
+
end # if HAVE_GIT
|
40
|
+
|
41
|
+
# EOF
|
data/tasks/manifest.rake
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
namespace :manifest do
|
6
|
+
|
7
|
+
desc 'Verify the manifest'
|
8
|
+
task :check do
|
9
|
+
fn = PROJ.manifest_file + '.tmp'
|
10
|
+
files = manifest_files
|
11
|
+
|
12
|
+
File.open(fn, 'w') {|fp| fp.puts files}
|
13
|
+
lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
|
14
|
+
if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
|
15
|
+
lines.map! do |line|
|
16
|
+
case line
|
17
|
+
when %r/^(-{3}|\+{3})/; nil
|
18
|
+
when %r/^@/; Console::ANSICode.blue line
|
19
|
+
when %r/^\+/; Console::ANSICode.green line
|
20
|
+
when %r/^\-/; Console::ANSICode.red line
|
21
|
+
else line end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
puts lines.compact
|
25
|
+
rm fn rescue nil
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Create a new manifest'
|
29
|
+
task :create do
|
30
|
+
files = manifest_files
|
31
|
+
unless test(?f, PROJ.manifest_file)
|
32
|
+
files << PROJ.manifest_file
|
33
|
+
files.sort!
|
34
|
+
end
|
35
|
+
File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
|
36
|
+
end
|
37
|
+
|
38
|
+
task :assert do
|
39
|
+
files = manifest_files
|
40
|
+
manifest = File.read(PROJ.manifest_file).split($/)
|
41
|
+
raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
|
42
|
+
end
|
43
|
+
|
44
|
+
end # namespace :manifest
|
45
|
+
|
46
|
+
desc 'Alias to manifest:check'
|
47
|
+
task :manifest => 'manifest:check'
|
48
|
+
|
49
|
+
# EOF
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
# This file does not define any rake tasks. It is used to load some project
|
4
|
+
# settings if they are not defined by the user.
|
5
|
+
|
6
|
+
PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
|
7
|
+
PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
|
8
|
+
"^#{Regexp.escape(PROJ.rdoc.dir)}/",
|
9
|
+
"^#{Regexp.escape(PROJ.rcov.dir)}/"]
|
10
|
+
|
11
|
+
flatten_arrays = lambda do |this,os|
|
12
|
+
os.instance_variable_get(:@table).each do |key,val|
|
13
|
+
next if key == :dependencies
|
14
|
+
case val
|
15
|
+
when Array; val.flatten!
|
16
|
+
when OpenStruct; this.call(this,val)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
flatten_arrays.call(flatten_arrays,PROJ)
|
21
|
+
|
22
|
+
PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
|
23
|
+
|
24
|
+
PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
|
25
|
+
|
26
|
+
PROJ.summary ||= PROJ.description.split('.').first
|
27
|
+
|
28
|
+
PROJ.gem.files ||=
|
29
|
+
if test(?f, PROJ.manifest_file)
|
30
|
+
files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
|
31
|
+
files.delete ''
|
32
|
+
files
|
33
|
+
else [] end
|
34
|
+
|
35
|
+
PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
|
36
|
+
|
37
|
+
PROJ.rdoc.main ||= PROJ.readme_file
|
38
|
+
|
39
|
+
# EOF
|
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
namespace :doc do
|
6
|
+
|
7
|
+
desc 'Generate RDoc documentation'
|
8
|
+
Rake::RDocTask.new do |rd|
|
9
|
+
rdoc = PROJ.rdoc
|
10
|
+
rd.main = rdoc.main
|
11
|
+
rd.rdoc_dir = rdoc.dir
|
12
|
+
|
13
|
+
incl = Regexp.new(rdoc.include.join('|'))
|
14
|
+
excl = Regexp.new(rdoc.exclude.join('|'))
|
15
|
+
files = PROJ.gem.files.find_all do |fn|
|
16
|
+
case fn
|
17
|
+
when excl; false
|
18
|
+
when incl; true
|
19
|
+
else false end
|
20
|
+
end
|
21
|
+
rd.rdoc_files.push(*files)
|
22
|
+
|
23
|
+
title = "#{PROJ.name}-#{PROJ.version} Documentation"
|
24
|
+
|
25
|
+
rf_name = PROJ.rubyforge.name
|
26
|
+
title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
|
27
|
+
|
28
|
+
rd.options << "-t #{title}"
|
29
|
+
rd.options.concat(rdoc.opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Generate ri locally for testing'
|
33
|
+
task :ri => :clobber_ri do
|
34
|
+
sh "#{RDOC} --ri -o ri ."
|
35
|
+
end
|
36
|
+
|
37
|
+
task :clobber_ri do
|
38
|
+
rm_r 'ri' rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
end # namespace :doc
|
42
|
+
|
43
|
+
desc 'Alias to doc:rdoc'
|
44
|
+
task :doc => 'doc:rdoc'
|
45
|
+
|
46
|
+
desc 'Remove all build products'
|
47
|
+
task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
|
48
|
+
|
49
|
+
remove_desc_for_task %w(doc:clobber_rdoc)
|
50
|
+
|
51
|
+
# EOF
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
|
3
|
+
|
4
|
+
require 'rubyforge'
|
5
|
+
require 'rake/contrib/sshpublisher'
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc 'Package and upload to RubyForge'
|
9
|
+
task :release => [:clobber, 'gem:package'] do |t|
|
10
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
11
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
12
|
+
pkg = "pkg/#{PROJ.gem._spec.full_name}"
|
13
|
+
|
14
|
+
if $DEBUG then
|
15
|
+
puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
|
16
|
+
puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
|
17
|
+
end
|
18
|
+
|
19
|
+
rf = RubyForge.new
|
20
|
+
rf.configure rescue nil
|
21
|
+
puts 'Logging in'
|
22
|
+
rf.login
|
23
|
+
|
24
|
+
c = rf.userconfig
|
25
|
+
c['release_notes'] = PROJ.description if PROJ.description
|
26
|
+
c['release_changes'] = PROJ.changes if PROJ.changes
|
27
|
+
c['preformatted'] = true
|
28
|
+
|
29
|
+
files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
|
30
|
+
(PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
|
31
|
+
"#{pkg}.gem"].compact
|
32
|
+
|
33
|
+
puts "Releasing #{PROJ.name} v. #{PROJ.version}"
|
34
|
+
rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
|
35
|
+
end
|
36
|
+
end # namespace :gem
|
37
|
+
|
38
|
+
|
39
|
+
namespace :doc do
|
40
|
+
desc "Publish RDoc to RubyForge"
|
41
|
+
task :release => %w(doc:clobber_rdoc doc:rdoc) do
|
42
|
+
config = YAML.load(
|
43
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
44
|
+
)
|
45
|
+
|
46
|
+
host = "#{config['username']}@rubyforge.org"
|
47
|
+
remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
|
48
|
+
remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
|
49
|
+
local_dir = PROJ.rdoc.dir
|
50
|
+
|
51
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
52
|
+
end
|
53
|
+
end # namespace :doc
|
54
|
+
|
55
|
+
end # if HAVE_RUBYFORGE
|
56
|
+
|
57
|
+
# EOF
|
data/tasks/setup.rb
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
class OpenStruct; undef :gem; end
|
10
|
+
|
11
|
+
PROJ = OpenStruct.new(
|
12
|
+
# Project Defaults
|
13
|
+
:name => nil,
|
14
|
+
:summary => nil,
|
15
|
+
:description => nil,
|
16
|
+
:changes => nil,
|
17
|
+
:authors => nil,
|
18
|
+
:email => nil,
|
19
|
+
:url => "\000",
|
20
|
+
:version => ENV['VERSION'] || '0.0.0',
|
21
|
+
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git ^pkg/),
|
22
|
+
:release_name => ENV['RELEASE'],
|
23
|
+
|
24
|
+
# System Defaults
|
25
|
+
:ruby_opts => %w(-w),
|
26
|
+
:libs => [],
|
27
|
+
:history_file => 'History.txt',
|
28
|
+
:manifest_file => 'Manifest.txt',
|
29
|
+
:readme_file => 'README.rdoc',
|
30
|
+
|
31
|
+
# Announce
|
32
|
+
:ann => OpenStruct.new(
|
33
|
+
:file => 'announcement.txt',
|
34
|
+
:text => nil,
|
35
|
+
:paragraphs => [],
|
36
|
+
:email => {
|
37
|
+
:from => nil,
|
38
|
+
:to => %w(ruby-talk@ruby-lang.org),
|
39
|
+
:server => 'localhost',
|
40
|
+
:port => 25,
|
41
|
+
:domain => ENV['HOSTNAME'],
|
42
|
+
:acct => nil,
|
43
|
+
:passwd => nil,
|
44
|
+
:authtype => :plain
|
45
|
+
}
|
46
|
+
),
|
47
|
+
|
48
|
+
# Gem Packaging
|
49
|
+
:gem => OpenStruct.new(
|
50
|
+
:dependencies => [],
|
51
|
+
:executables => nil,
|
52
|
+
:extensions => FileList['ext/**/extconf.rb'],
|
53
|
+
:files => nil,
|
54
|
+
:need_tar => true,
|
55
|
+
:need_zip => false,
|
56
|
+
:extras => {}
|
57
|
+
),
|
58
|
+
|
59
|
+
# File Annotations
|
60
|
+
:notes => OpenStruct.new(
|
61
|
+
:exclude => %w(^tasks/setup\.rb$),
|
62
|
+
:extensions => %w(.txt .rb .erb) << '',
|
63
|
+
:tags => %w(FIXME OPTIMIZE TODO)
|
64
|
+
),
|
65
|
+
|
66
|
+
# Rcov
|
67
|
+
:rcov => OpenStruct.new(
|
68
|
+
:dir => 'coverage',
|
69
|
+
:opts => %w[--sort coverage -T],
|
70
|
+
:threshold => 90.0,
|
71
|
+
:threshold_exact => false
|
72
|
+
),
|
73
|
+
|
74
|
+
# Rdoc
|
75
|
+
:rdoc => OpenStruct.new(
|
76
|
+
:opts => [],
|
77
|
+
:include => %w(^lib/ ^bin/ ^ext/ \.txt$),
|
78
|
+
:exclude => %w(extconf\.rb$),
|
79
|
+
:main => nil,
|
80
|
+
:dir => 'doc',
|
81
|
+
:remote_dir => nil
|
82
|
+
),
|
83
|
+
|
84
|
+
# Rubyforge
|
85
|
+
:rubyforge => OpenStruct.new(
|
86
|
+
:name => "\000"
|
87
|
+
),
|
88
|
+
|
89
|
+
# Rspec
|
90
|
+
:spec => OpenStruct.new(
|
91
|
+
:files => FileList['spec/**/*_spec.rb'],
|
92
|
+
:opts => []
|
93
|
+
),
|
94
|
+
|
95
|
+
# Subversion Repository
|
96
|
+
:svn => OpenStruct.new(
|
97
|
+
:root => nil,
|
98
|
+
:path => '',
|
99
|
+
:trunk => 'trunk',
|
100
|
+
:tags => 'tags',
|
101
|
+
:branches => 'branches'
|
102
|
+
),
|
103
|
+
|
104
|
+
# Test::Unit
|
105
|
+
:test => OpenStruct.new(
|
106
|
+
:files => FileList['test/**/test_*.rb'],
|
107
|
+
:file => 'test/all.rb',
|
108
|
+
:opts => []
|
109
|
+
)
|
110
|
+
)
|
111
|
+
|
112
|
+
# Load the other rake files in the tasks folder
|
113
|
+
rakefiles = Dir.glob('tasks/*.rake').sort
|
114
|
+
rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
|
115
|
+
import(*rakefiles)
|
116
|
+
|
117
|
+
# Setup the project libraries
|
118
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
119
|
+
|
120
|
+
# Setup some constants
|
121
|
+
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
|
122
|
+
|
123
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
124
|
+
|
125
|
+
def quiet( &block )
|
126
|
+
io = [STDOUT.dup, STDERR.dup]
|
127
|
+
STDOUT.reopen DEV_NULL
|
128
|
+
STDERR.reopen DEV_NULL
|
129
|
+
block.call
|
130
|
+
ensure
|
131
|
+
STDOUT.reopen io.first
|
132
|
+
STDERR.reopen io.last
|
133
|
+
$stdout, $stderr = STDOUT, STDERR
|
134
|
+
end
|
135
|
+
|
136
|
+
DIFF = if WIN32 then 'diff.exe'
|
137
|
+
else
|
138
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
139
|
+
else 'diff' end
|
140
|
+
end unless defined? DIFF
|
141
|
+
|
142
|
+
SUDO = if WIN32 then ''
|
143
|
+
else
|
144
|
+
if quiet {system 'which sudo'} then 'sudo'
|
145
|
+
else '' end
|
146
|
+
end
|
147
|
+
|
148
|
+
RCOV = WIN32 ? 'rcov.bat' : 'rcov'
|
149
|
+
RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
|
150
|
+
GEM = WIN32 ? 'gem.bat' : 'gem'
|
151
|
+
|
152
|
+
%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
|
153
|
+
begin
|
154
|
+
require lib
|
155
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
|
156
|
+
rescue LoadError
|
157
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
|
161
|
+
system("svn --version 2>&1 > #{DEV_NULL}"))
|
162
|
+
HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
|
163
|
+
system("git --version 2>&1 > #{DEV_NULL}"))
|
164
|
+
|
165
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
166
|
+
# specified.
|
167
|
+
#
|
168
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
169
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
170
|
+
#
|
171
|
+
def paragraphs_of( path, *paragraphs )
|
172
|
+
title = String === paragraphs.first ? paragraphs.shift : nil
|
173
|
+
ary = File.read(path).delete("\r").split(/\n\n+/)
|
174
|
+
|
175
|
+
result = if title
|
176
|
+
tmp, matching = [], false
|
177
|
+
rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
|
178
|
+
paragraphs << (0..-1) if paragraphs.empty?
|
179
|
+
|
180
|
+
ary.each do |val|
|
181
|
+
if val =~ rgxp
|
182
|
+
break if matching
|
183
|
+
matching = true
|
184
|
+
rgxp = %r/^=+/i
|
185
|
+
elsif matching
|
186
|
+
tmp << val
|
187
|
+
end
|
188
|
+
end
|
189
|
+
tmp
|
190
|
+
else ary end
|
191
|
+
|
192
|
+
result.values_at(*paragraphs)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
196
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
197
|
+
# will be used.
|
198
|
+
#
|
199
|
+
def depend_on( name, version = nil )
|
200
|
+
spec = Gem.source_index.find_name(name).last
|
201
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
202
|
+
|
203
|
+
PROJ.gem.dependencies << case version
|
204
|
+
when nil; [name]
|
205
|
+
when %r/^\d/; [name, ">= #{version}"]
|
206
|
+
else [name, version] end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Adds the given arguments to the include path if they are not already there
|
210
|
+
#
|
211
|
+
def ensure_in_path( *args )
|
212
|
+
args.each do |path|
|
213
|
+
path = File.expand_path(path)
|
214
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Find a rake task using the task name and remove any description text. This
|
219
|
+
# will prevent the task from being displayed in the list of available tasks.
|
220
|
+
#
|
221
|
+
def remove_desc_for_task( names )
|
222
|
+
Array(names).each do |task_name|
|
223
|
+
task = Rake.application.tasks.find {|t| t.name == task_name}
|
224
|
+
next if task.nil?
|
225
|
+
task.instance_variable_set :@comment, nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Change working directories to _dir_, call the _block_ of code, and then
|
230
|
+
# change back to the original working directory (the current directory when
|
231
|
+
# this method was called).
|
232
|
+
#
|
233
|
+
def in_directory( dir, &block )
|
234
|
+
curdir = pwd
|
235
|
+
begin
|
236
|
+
cd dir
|
237
|
+
return block.call
|
238
|
+
ensure
|
239
|
+
cd curdir
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Scans the current working directory and creates a list of files that are
|
244
|
+
# candidates to be in the manifest.
|
245
|
+
#
|
246
|
+
def manifest_files
|
247
|
+
files = []
|
248
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
249
|
+
Find.find '.' do |path|
|
250
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
251
|
+
next unless test ?f, path
|
252
|
+
next if path =~ exclude
|
253
|
+
files << path
|
254
|
+
end
|
255
|
+
files.sort!
|
256
|
+
end
|
257
|
+
|
258
|
+
# We need a "valid" method thtat determines if a string is suitable for use
|
259
|
+
# in the gem specification.
|
260
|
+
#
|
261
|
+
class Object
|
262
|
+
def valid?
|
263
|
+
return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
namespace :test do
|
4
|
+
|
5
|
+
Rake::TestTask.new(:run) do |t|
|
6
|
+
t.libs = PROJ.libs
|
7
|
+
t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
8
|
+
else PROJ.test.files end
|
9
|
+
t.ruby_opts += PROJ.ruby_opts
|
10
|
+
t.ruby_opts += PROJ.test.opts
|
11
|
+
end
|
12
|
+
|
13
|
+
if HAVE_RCOV
|
14
|
+
desc 'Run rcov on the unit tests'
|
15
|
+
task :rcov => :clobber_rcov do
|
16
|
+
opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
|
17
|
+
opts = opts.join(' ')
|
18
|
+
files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
19
|
+
else PROJ.test.files end
|
20
|
+
files = files.join(' ')
|
21
|
+
sh "#{RCOV} #{files} #{opts}"
|
22
|
+
end
|
23
|
+
|
24
|
+
task :clobber_rcov do
|
25
|
+
rm_r 'coverage' rescue nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end # namespace :test
|
30
|
+
|
31
|
+
desc 'Alias to test:run'
|
32
|
+
task :test => 'test:run'
|
33
|
+
|
34
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ActsAsMarkdownTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
setup_db
|
6
|
+
@md_text = '## Markdown Test Text'
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'using RDiscount' do
|
10
|
+
setup do
|
11
|
+
ActsAsMarkdown.markdown_library = :rdiscount
|
12
|
+
class ::Post < ActiveRecord::Base
|
13
|
+
acts_as_markdown :body
|
14
|
+
end
|
15
|
+
@post = Post.create!(:title => 'Blah', :body => @md_text)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "have a RDiscount object returned for the column value" do
|
19
|
+
assert_kind_of RDiscount, @post.body
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
23
|
+
assert_equal @md_text, @post.body.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
should "return formated html for a `to_html` method call on teh column value" do
|
27
|
+
assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
28
|
+
end
|
29
|
+
|
30
|
+
teardown do
|
31
|
+
@post = nil
|
32
|
+
Post.delete_all
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'using Ruby PEG Markdown' do
|
37
|
+
setup do
|
38
|
+
ActsAsMarkdown.markdown_library = :rpeg
|
39
|
+
class ::Post < ActiveRecord::Base
|
40
|
+
acts_as_markdown :body
|
41
|
+
end
|
42
|
+
@post = Post.create!(:title => 'Blah', :body => @md_text)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "have a Ruby PEG Markdown object returned for the column value" do
|
46
|
+
assert_kind_of PEGMarkdown, @post.body
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
50
|
+
assert_equal @md_text, @post.body.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return formated html for a `to_html` method call on teh column value" do
|
54
|
+
assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
55
|
+
end
|
56
|
+
|
57
|
+
teardown do
|
58
|
+
@post = nil
|
59
|
+
Post.delete_all
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'using BlueCloth' do
|
64
|
+
setup do
|
65
|
+
ActsAsMarkdown.markdown_library = :bluecloth
|
66
|
+
class ::Post < ActiveRecord::Base
|
67
|
+
acts_as_markdown :body
|
68
|
+
end
|
69
|
+
@post = Post.create!(:title => 'Blah', :body => @md_text)
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have a BlueCloth object returned for the column value" do
|
73
|
+
assert_kind_of BlueCloth, @post.body
|
74
|
+
end
|
75
|
+
|
76
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
77
|
+
assert_equal @md_text, @post.body.to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
should "return formated html for a `to_html` method call on teh column value" do
|
81
|
+
assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
82
|
+
end
|
83
|
+
|
84
|
+
teardown do
|
85
|
+
@post = nil
|
86
|
+
Post.delete_all
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
teardown_db
|
92
|
+
@md_text = nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'shoulda'
|
3
|
+
require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib acts_as_markdown]) )
|
4
|
+
|
5
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
6
|
+
|
7
|
+
def setup_db
|
8
|
+
ActiveRecord::Schema.define(:version => 1) do
|
9
|
+
create_table :posts do |t|
|
10
|
+
t.column :title, :string
|
11
|
+
t.column :body, :text
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown_db
|
18
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
19
|
+
ActiveRecord::Base.connection.drop_table(table)
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_markdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Landau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-04 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Represent ActiveRecord markdown text columns as Markdown objects using various external libraries to convert to HTML.
|
17
|
+
email: brian.landau@viget.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- LICENSE.txt
|
28
|
+
- Manifest.txt
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- acts_as_markdown.gemspec
|
32
|
+
- lib/acts/as_markdown.rb
|
33
|
+
- lib/acts_as_markdown.rb
|
34
|
+
- lib/acts_as_markdown/exts/rdiscount.rb
|
35
|
+
- tasks/bones.rake
|
36
|
+
- tasks/gem.rake
|
37
|
+
- tasks/git.rake
|
38
|
+
- tasks/manifest.rake
|
39
|
+
- tasks/post_load.rake
|
40
|
+
- tasks/rdoc.rake
|
41
|
+
- tasks/rubyforge.rake
|
42
|
+
- tasks/setup.rb
|
43
|
+
- tasks/test.rake
|
44
|
+
- test/acts_as_markdown_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://viget.rubyforge.com/acts_as_markdown
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --main
|
51
|
+
- README.rdoc
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: viget
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: Represent ActiveRecord markdown text columns as Markdown objects using various external libraries to convert to HTML
|
73
|
+
test_files:
|
74
|
+
- test/acts_as_markdown_test.rb
|