aq1018-dm-is-markup 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 +3 -0
- data/LICENSE +20 -0
- data/Manifest.txt +9 -0
- data/README.txt +3 -0
- data/Rakefile +52 -0
- data/TODO +1 -0
- data/lib/dm-is-markup.rb +19 -0
- data/lib/dm-is-markup/is/markup.rb +96 -0
- data/lib/dm-is-markup/is/version.rb +7 -0
- metadata +84 -0
data/History.txt
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Aaron Qian
|
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
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
7
|
+
require ROOT + 'lib/dm-is-markup/is/version'
|
8
|
+
|
9
|
+
AUTHOR = "Aaron Qian, Brian Smith"
|
10
|
+
EMAIL = "aaron [a] ekohe [d] com; wbsmith83 [a] gmail [d] com"
|
11
|
+
GEM_NAME = "dm-is-markup"
|
12
|
+
GEM_VERSION = DataMapper::Is::Markup::VERSION
|
13
|
+
GEM_DEPENDENCIES = [["dm-core", "~>0.9"]]
|
14
|
+
GEM_CLEAN = ["log", "pkg"]
|
15
|
+
GEM_EXTRAS = { :has_rdoc => false }
|
16
|
+
|
17
|
+
PROJECT_NAME = "dm-is-slug"
|
18
|
+
PROJECT_URL = "http://github.com/aq1018/dm-is-markup"
|
19
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "Parse a field with a markup engine and save it to a new field created by the plugin."
|
20
|
+
|
21
|
+
require 'tasks/hoe'
|
22
|
+
|
23
|
+
task :default => [ :spec ]
|
24
|
+
|
25
|
+
WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
|
26
|
+
SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
|
27
|
+
|
28
|
+
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
29
|
+
task :install => [ :package ] do
|
30
|
+
sh "#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources", :verbose => false
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
|
34
|
+
task :uninstall => [ :clobber ] do
|
35
|
+
sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Run specifications'
|
39
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
40
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
41
|
+
t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + 'spec/**/*_spec.rb')
|
42
|
+
|
43
|
+
begin
|
44
|
+
t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
|
45
|
+
t.rcov_opts << '--exclude' << 'spec'
|
46
|
+
t.rcov_opts << '--text-summary'
|
47
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
48
|
+
rescue Exception
|
49
|
+
puts 'rcov is not installed. Please install before continuing'
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
data/lib/dm-is-markup.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Needed to import datamapper and other gems
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Add all external dependencies for the plugin here
|
6
|
+
require 'dm-core'
|
7
|
+
|
8
|
+
# Require plugin-files
|
9
|
+
require Pathname(__FILE__).dirname.expand_path / 'dm-is-markup' / 'is' / 'markup.rb'
|
10
|
+
|
11
|
+
|
12
|
+
# Include the plugin in Resource
|
13
|
+
module DataMapper
|
14
|
+
module Resource
|
15
|
+
module ClassMethods
|
16
|
+
include DataMapper::Is::Markup
|
17
|
+
end # module ClassMethods
|
18
|
+
end # module Resource
|
19
|
+
end # module DataMapper
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Is
|
3
|
+
module Markup
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def is_markup(options)
|
10
|
+
extend DataMapper::Is::Markup::ClassMethods
|
11
|
+
include DataMapper::Is::Markup::InstanceMethods
|
12
|
+
|
13
|
+
#merge in default options
|
14
|
+
options = {
|
15
|
+
:filter_property => :filter_type,
|
16
|
+
:markup_property => "#{options[:source]}_html".to_sym
|
17
|
+
}.merge(options)
|
18
|
+
|
19
|
+
# must at least specify a source property to generate the filtered Text
|
20
|
+
raise Exception.new("You must specify a :source") unless options.include?(:source)
|
21
|
+
|
22
|
+
# save as class variable for later...
|
23
|
+
@markup_options = options
|
24
|
+
|
25
|
+
# make sure the source property exsists
|
26
|
+
source_property = properties.detect{|p| p.name == options[:source].to_sym && p.type == DM::Text}
|
27
|
+
|
28
|
+
existing_markup_property = properties.detect{|p| p.name == options[:markup_property].to_sym}
|
29
|
+
existing_filter_property = properties.detect{|p| p.name == options[:filter_property].to_sym}
|
30
|
+
|
31
|
+
unless existing_markup_property || existing_filter_property
|
32
|
+
property markup_property, DM::Text
|
33
|
+
property filter_property, DM::Enum[:textile, :markdown, :wikitext], :nullable => false, :default => :textile
|
34
|
+
else
|
35
|
+
raise Exception.new("#{markup_property} or #{filter_property} has been defined as property already!")
|
36
|
+
end
|
37
|
+
|
38
|
+
before :save, :apply_filter
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
module ClassMethods
|
43
|
+
attr_reader :markup_options
|
44
|
+
|
45
|
+
def markup_property
|
46
|
+
markup_options[:markup_property]
|
47
|
+
end
|
48
|
+
|
49
|
+
def filter_property
|
50
|
+
markup_options[:filter_property]
|
51
|
+
end
|
52
|
+
|
53
|
+
def source_property
|
54
|
+
markup_options[:source]
|
55
|
+
end
|
56
|
+
|
57
|
+
end # ClassMethods
|
58
|
+
|
59
|
+
module InstanceMethods
|
60
|
+
|
61
|
+
def markup_property
|
62
|
+
self.send(self.class.markup_property)
|
63
|
+
end
|
64
|
+
|
65
|
+
def filter_property
|
66
|
+
self.send(self.class.markup_property)
|
67
|
+
end
|
68
|
+
|
69
|
+
def source_property
|
70
|
+
self.send(self.class.source_property)
|
71
|
+
end
|
72
|
+
|
73
|
+
def apply_filter
|
74
|
+
if new_record? || attribute_dirty?(self.class.source_property) || attribute_dirty?(self.class.filter_property)
|
75
|
+
attribute_set(self.class.markup_property, generate_markup(self.send(:filter_type)))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate_markup(filter)
|
80
|
+
case filter
|
81
|
+
when :textile:
|
82
|
+
RedCloth.new(source_property).to_html
|
83
|
+
when :markdown:
|
84
|
+
BlueCloth.new(source_property).to_html
|
85
|
+
when :wikitext:
|
86
|
+
Wikitext::Parser.new.parse(source_property)
|
87
|
+
else
|
88
|
+
raise Exception.new("Unknown Filter!! use textile, markdown or wikitext as filters only")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end # InstanceMethods
|
93
|
+
|
94
|
+
end # Markup
|
95
|
+
end # Is
|
96
|
+
end # DataMapper
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aq1018-dm-is-markup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Qian, Brian Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-26 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.9"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.2
|
34
|
+
version:
|
35
|
+
description: Parse a field with a markup engine and save it to a new field created by the plugin.
|
36
|
+
email:
|
37
|
+
- aaron [a] ekohe [d] com; wbsmith83 [a] gmail [d] com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.txt
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- LICENSE
|
49
|
+
- Manifest.txt
|
50
|
+
- README.txt
|
51
|
+
- Rakefile
|
52
|
+
- TODO
|
53
|
+
- lib/dm-is-markup.rb
|
54
|
+
- lib/dm-is-markup/is/markup.rb
|
55
|
+
- lib/dm-is-markup/is/version.rb
|
56
|
+
has_rdoc: false
|
57
|
+
homepage: http://github.com/aq1018/dm-is-markup
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --main
|
61
|
+
- README.txt
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: dm-is-slug
|
79
|
+
rubygems_version: 1.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: Parse a field with a markup engine and save it to a new field created by the plugin.
|
83
|
+
test_files: []
|
84
|
+
|