radiant-markdown_filter-extension 1.0.0

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/README ADDED
@@ -0,0 +1 @@
1
+ Adds support for Markdown!
data/Rakefile ADDED
@@ -0,0 +1,120 @@
1
+ # I think this is the one that should be moved to the extension Rakefile template
2
+
3
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
4
+ # Check to see if the rspec plugin is installed first and require
5
+ # it if it is. If not, use the gem version.
6
+
7
+ # Determine where the RSpec plugin is by loading the boot
8
+ unless defined? RADIANT_ROOT
9
+ ENV["RAILS_ENV"] = "test"
10
+ case
11
+ when ENV["RADIANT_ENV_FILE"]
12
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
13
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
14
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
15
+ else
16
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
17
+ end
18
+ end
19
+
20
+ require 'rake'
21
+ require 'rake/rdoctask'
22
+ require 'rake/testtask'
23
+
24
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
25
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
26
+ require 'spec/rake/spectask'
27
+ # require 'spec/translator'
28
+
29
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
30
+ Object.send(:remove_const, :RADIANT_ROOT)
31
+
32
+ extension_root = File.expand_path(File.dirname(__FILE__))
33
+
34
+ task :default => :spec
35
+ task :stats => "spec:statsetup"
36
+
37
+ desc "Run all specs in spec directory"
38
+ Spec::Rake::SpecTask.new(:spec) do |t|
39
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ namespace :spec do
44
+ desc "Run all specs in spec directory with RCov"
45
+ Spec::Rake::SpecTask.new(:rcov) do |t|
46
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
47
+ t.spec_files = FileList['spec/**/*_spec.rb']
48
+ t.rcov = true
49
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
50
+ end
51
+
52
+ desc "Print Specdoc for all specs"
53
+ Spec::Rake::SpecTask.new(:doc) do |t|
54
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ end
57
+
58
+ [:models, :controllers, :views, :helpers].each do |sub|
59
+ desc "Run the specs under spec/#{sub}"
60
+ Spec::Rake::SpecTask.new(sub) do |t|
61
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
62
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
63
+ end
64
+ end
65
+
66
+ # Hopefully no one has written their extensions in pre-0.9 style
67
+ # desc "Translate specs from pre-0.9 to 0.9 style"
68
+ # task :translate do
69
+ # translator = ::Spec::Translator.new
70
+ # dir = RAILS_ROOT + '/spec'
71
+ # translator.translate(dir, dir)
72
+ # end
73
+
74
+ # Setup specs for stats
75
+ task :statsetup do
76
+ require 'code_statistics'
77
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
78
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
79
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
80
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
81
+ ::CodeStatistics::TEST_TYPES << "Model specs"
82
+ ::CodeStatistics::TEST_TYPES << "View specs"
83
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
84
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
85
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86
+ end
87
+
88
+ namespace :db do
89
+ namespace :fixtures do
90
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91
+ task :load => :environment do
92
+ require 'active_record/fixtures'
93
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc 'Generate documentation for the <%= file_name %> extension.'
103
+ Rake::RDocTask.new(:rdoc) do |rdoc|
104
+ rdoc.rdoc_dir = 'rdoc'
105
+ rdoc.title = '<%= class_name %>'
106
+ rdoc.options << '--line-numbers' << '--inline-source'
107
+ rdoc.rdoc_files.include('README')
108
+ rdoc.rdoc_files.include('lib/**/*.rb')
109
+ end
110
+
111
+ # For extensions that are in transition
112
+ desc 'Test the <%= file_name %> extension.'
113
+ Rake::TestTask.new(:test) do |t|
114
+ t.libs << 'lib'
115
+ t.pattern = 'test/**/*_test.rb'
116
+ t.verbose = true
117
+ end
118
+
119
+ # Load any custom rakefiles for extension
120
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,6 @@
1
+ class MarkdownFilter < TextFilter
2
+ description_file File.dirname(__FILE__) + "/../markdown.html"
3
+ def filter(text)
4
+ BlueCloth.new(text, :smartypants => true).to_html
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module MarkdownTags
2
+ include Radiant::Taggable
3
+
4
+ desc %{
5
+ Filters its contents with the Markdown filter.
6
+
7
+ *Usage:*
8
+
9
+ <pre><code><r:markdown>** bold text **</r:markdown></code></pre>
10
+
11
+ produces
12
+
13
+ <pre><code><strong> bold text </strong></code></pre>
14
+ }
15
+ tag 'markdown' do |tag|
16
+ MarkdownFilter.filter(tag.expand)
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module RadiantMarkdownFilterExtension
2
+ VERSION = "1.0.0"
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ module RadiantMarkdownFilterExtension
2
+ end
3
+
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :markdown_filter do
4
+
5
+ desc "Runs the migration of the Markdown Filter extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ MarkdownFilterExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ MarkdownFilterExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the Markdown Filter to the instance public/ directory."
16
+ task :update => :environment do
17
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
18
+ Dir[MarkdownFilterExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
19
+ path = file.sub(MarkdownFilterExtension.root, '')
20
+ directory = File.dirname(path)
21
+ puts "Copying #{path}..."
22
+ mkdir_p RAILS_ROOT + directory
23
+ cp file, RAILS_ROOT + path
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
data/markdown.html ADDED
@@ -0,0 +1,123 @@
1
+ <p>Many people prefer <a href="http://daringfireball.net/projects/markdown/" target="_blank">Markdown</a>
2
+ over standard HTML because it is less verbose. Unlike Textile, Markdown
3
+ doesn&#8217;t try to replicate all of the features implemented by regular
4
+ HTML, instead it encourages the use of inline HTML. Markdown is very similar
5
+ to the formatting used in a standard plain-text e-mail. This filter also uses
6
+ <a href="http://daringfireball.net/projects/smartypants/" target="_blank">SmartyPants</a>
7
+ to curl quotes and insert correct punctuation.</p>
8
+
9
+ <table id="filter-reference-table">
10
+ <thead>
11
+ <tr>
12
+ <th>To see this:</th>
13
+ <th>Type this:</th>
14
+ <tr>
15
+ </thead>
16
+ <tbody>
17
+ <tr>
18
+ <td><strong>bold</strong></td>
19
+ <td><pre>**bold**</pre></td>
20
+ </tr>
21
+ <tr>
22
+ <td><em>italics</em></td>
23
+ <td><pre>_italics_</pre></td>
24
+ </tr>
25
+ <tr>
26
+ <td><del>strikethrough</del></td>
27
+ <td><pre>&lt;del&gt;strikethrough&lt;/del&gt;</pre></td>
28
+ </tr>
29
+ <tr>
30
+ <td>x<sup>superscript</sup></td>
31
+ <td><pre>x&lt;sup&gt;superscript&lt;/sup&gt;</pre></td>
32
+ </tr>
33
+ <tr>
34
+ <td>a<sub>subscript</sub></td>
35
+ <td><pre>a&lt;sub&gt;subscript&lt;/sub&gt;</pre></td>
36
+ </tr>
37
+ <tr>
38
+ <td><code>code phrase</code></td>
39
+ <td><pre>`code phrase`</pre></td>
40
+ </tr>
41
+ <tr>
42
+ <td>link to <a href="http://radiantcms.org">Radiant CMS</a></td>
43
+ <td><pre>link to [Radiant CMS](http://radiantcms.org)</pre></td>
44
+ </tr>
45
+ <tr>
46
+ <td><acronym title="Just Another Acronym">JAA</acronym></td>
47
+ <td><pre>&lt;acronym title="Just Another Acronym"&gt;JAA&lt;/acronym&gt;</td>
48
+ </tr>
49
+ <tr>
50
+ <td><span style="color:red">Red Text</span></td>
51
+ <td><pre>&lt;span style="color:red"&gt;Red Text&lt;/span&gt;</pre></td>
52
+ </tr>
53
+ <tr>
54
+ <td>
55
+ <p>A bulleted list:</p>
56
+ <ul>
57
+ <li>item one</li>
58
+ <li>item two</li>
59
+ <li>item three</li>
60
+ </ul>
61
+ </td>
62
+ <td>
63
+ <pre>A bulleted list:
64
+ * item one
65
+ * item two
66
+ * item three</pre>
67
+ </td>
68
+ </tr>
69
+ <tr>
70
+ <td>
71
+ <p>A numbered list:</p>
72
+ <ol>
73
+ <li>item one</li>
74
+ <li>item two</li>
75
+ <li>item three</li>
76
+ </ol>
77
+ </td>
78
+ <td>
79
+ <pre>A numbered list:
80
+ 1. item one
81
+ 2. item two
82
+ 3. item three</pre>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td>
87
+ <h1>Heading 1</h1>
88
+ <h2>Heading 2</h2>
89
+ <h3>Heading 3</h3>
90
+ <h4>Heading 4</h4>
91
+ </td>
92
+ <td>
93
+ <pre>Heading 1
94
+ ---------
95
+
96
+ Heading 2
97
+ =========
98
+
99
+ ### Heading 3
100
+
101
+ #### Heading 4</pre>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td><blockquote>Roses are red, violets are blue, Markdown is nice, and so are you!</blockquote></td>
106
+ <td>
107
+ <pre>&gt; Roses are red,
108
+ &gt; violets are blue,
109
+ &gt; Markdown is nice,
110
+ &gt; and so are you!</pre>
111
+ </tr>
112
+ <tr>
113
+ <td><img src="/../images/radiant/radiant-badge-color.png" alt="" /></td>
114
+ <td><pre>![alt text](/images/radiant/radiant-badge-color.png)</pre></td>
115
+ </tr>
116
+ </tbody>
117
+ </table>
118
+
119
+ <p>Advanced users may want to play around with the
120
+ <a href="http://daringfireball.net/projects/markdown/dingus/" target="_blank">Markdown
121
+ Dingus</a> or review the
122
+ <a href="http://daringfireball.net/projects/markdown/syntax/" target="_blank">official Markdown
123
+ Reference</a>.</p>
@@ -0,0 +1,12 @@
1
+ require "bluecloth"
2
+
3
+ class MarkdownFilterExtension < Radiant::Extension
4
+ version "1.0.0"
5
+ description "Allows you to compose page parts or snippets using the Markdown text filter."
6
+ url "http://daringfireball.net/projects/markdown/"
7
+
8
+ def activate
9
+ MarkdownFilter
10
+ Page.send :include, MarkdownTags
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-markdown_filter-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-markdown_filter-extension"
7
+ s.version = RadiantMarkdownFilterExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Radiant CMS Dev Team"]
10
+ s.email = ["radiant@radiantcms.org"]
11
+ s.homepage = "http://radiantcms.org/"
12
+ s.summary = %q{Markdown Filter for Radiant CMS}
13
+ s.description = %q{Allows you to compose page parts or snippets using the Markdown text filter.}
14
+
15
+ ignores = if File.exist?(".gitignore")
16
+ File.read(".gitignore").split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir["**/*"] - ignores
21
+ s.test_files = Dir["test/**/*","spec/**/*","features/**/*"] - ignores
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency "bluecloth", "~> 2.1.0"
25
+
26
+ s.post_install_message = %{
27
+ Add this to your radiant project with:
28
+ config.gem "radiant-markdown_filter-extension", :version => "~> #{RadiantMarkdownFilterExtension::VERSION}"
29
+ }
30
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MarkdownFilter do
4
+ it "should be named Markdown" do
5
+ MarkdownFilter.filter_name.should == "Markdown"
6
+ end
7
+
8
+ it "should filter text according to Markdown rules" do
9
+ MarkdownFilter.filter('**strong**').should =~ %r{<p><strong>strong</strong></p>}
10
+ end
11
+
12
+ it "should filter text with quotes into smart quotes" do
13
+ MarkdownFilter.filter("# Radiant's \"filters\" rock!").should =~ %r{<h1>Radiant&(#8217|rsquo);s &(#8220|ldquo);filters&(#8221|rdquo); rock!</h1>}
14
+ end
15
+ end
16
+
17
+ describe "<r:markdown>" do
18
+ dataset :pages
19
+ it "should filter its contents with Markdown" do
20
+ pages(:home).should render("<r:markdown>* item</r:markdown>").matching(%r{<ul>\n(\s+)?<li>item<\/li>\n<\/ul>\n(\n)?})
21
+ end
22
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ # Load the environment
3
+ unless defined? RADIANT_ROOT
4
+ ENV["RAILS_ENV"] = "test"
5
+ case
6
+ when ENV["RADIANT_ENV_FILE"]
7
+ require ENV["RADIANT_ENV_FILE"]
8
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
10
+ else
11
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
12
+ end
13
+ end
14
+ require "#{RADIANT_ROOT}/test/test_helper"
15
+
16
+ class Test::Unit::TestCase
17
+ self.use_transactional_fixtures = true
18
+ self.use_instantiated_fixtures = false
19
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MarkdownFilterTest < Test::Unit::TestCase
4
+
5
+ def test_filter_name
6
+ assert_equal 'Markdown', MarkdownFilter.filter_name
7
+ end
8
+
9
+ def test_filter
10
+ assert_equal '<p><strong>strong</strong></p>', MarkdownFilter.filter('**strong**')
11
+ end
12
+
13
+ def test_filter_with_quotes
14
+ assert_equal "<h1>Radiant&#8217;s &#8220;filters&#8221; rock!</h1>",
15
+ MarkdownFilter.filter("# Radiant's \"filters\" rock!")
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-markdown_filter-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Radiant CMS Dev Team
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-12 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bluecloth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 2
32
+ - 1
33
+ - 0
34
+ version: 2.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Allows you to compose page parts or snippets using the Markdown text filter.
38
+ email:
39
+ - radiant@radiantcms.org
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/markdown_filter.rb
48
+ - lib/markdown_tags.rb
49
+ - lib/radiant-markdown_filter-extension/version.rb
50
+ - lib/radiant-markdown_filter-extension.rb
51
+ - lib/tasks/markdown_filter_extension_tasks.rake
52
+ - markdown.html
53
+ - markdown_filter_extension.rb
54
+ - radiant-markdown_filter-extension.gemspec
55
+ - Rakefile
56
+ - README
57
+ - spec/models/markdown_filter_spec.rb
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ - test/test_helper.rb
61
+ - test/unit/markdown_filter_test.rb
62
+ has_rdoc: true
63
+ homepage: http://radiantcms.org/
64
+ licenses: []
65
+
66
+ post_install_message: "\n Add this to your radiant project with:\n config.gem \"radiant-markdown_filter-extension\", :version => \"~> 1.0.0\"\n "
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.6.2
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Markdown Filter for Radiant CMS
96
+ test_files:
97
+ - test/test_helper.rb
98
+ - test/unit/markdown_filter_test.rb
99
+ - spec/models/markdown_filter_spec.rb
100
+ - spec/spec.opts
101
+ - spec/spec_helper.rb