radiant-smarty_pants_filter-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1 @@
1
+ Adds support for SmartyPants!
data/Rakefile ADDED
@@ -0,0 +1,136 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-smarty_pants_filter-extension"
5
+ gem.summary = %Q{Smarty Pants Filter Extension for Radiant CMS}
6
+ gem.description = %Q{Allows you to compose page parts or snippets using the SmartyPants text filter.}
7
+ gem.email = "radiant@radiantcms.org"
8
+ gem.homepage = "http://github.com/radiant/radiant-smarty_pants_filter-extension"
9
+ gem.authors = ["Radiant CMS dev team"]
10
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
11
+ end
12
+ rescue LoadError
13
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package smarty_pants_filter as a gem."
14
+ end
15
+
16
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
17
+ # Check to see if the rspec plugin is installed first and require
18
+ # it if it is. If not, use the gem version.
19
+
20
+ # Determine where the RSpec plugin is by loading the boot
21
+ unless defined? RADIANT_ROOT
22
+ ENV["RAILS_ENV"] = "test"
23
+ case
24
+ when ENV["RADIANT_ENV_FILE"]
25
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
26
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
27
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
28
+ else
29
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
30
+ end
31
+ end
32
+
33
+ require 'rake'
34
+ require 'rake/rdoctask'
35
+ require 'rake/testtask'
36
+
37
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
38
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
39
+ require 'spec/rake/spectask'
40
+ require 'cucumber'
41
+ require 'cucumber/rake/task'
42
+
43
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
44
+ Object.send(:remove_const, :RADIANT_ROOT)
45
+
46
+ extension_root = File.expand_path(File.dirname(__FILE__))
47
+
48
+ task :default => :spec
49
+ task :stats => "spec:statsetup"
50
+
51
+ desc "Run all specs in spec directory"
52
+ Spec::Rake::SpecTask.new(:spec) do |t|
53
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
54
+ t.spec_files = FileList['spec/**/*_spec.rb']
55
+ end
56
+
57
+ task :features => 'spec:integration'
58
+
59
+ namespace :spec do
60
+ desc "Run all specs in spec directory with RCov"
61
+ Spec::Rake::SpecTask.new(:rcov) do |t|
62
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
63
+ t.spec_files = FileList['spec/**/*_spec.rb']
64
+ t.rcov = true
65
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
66
+ end
67
+
68
+ desc "Print Specdoc for all specs"
69
+ Spec::Rake::SpecTask.new(:doc) do |t|
70
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
71
+ t.spec_files = FileList['spec/**/*_spec.rb']
72
+ end
73
+
74
+ [:models, :controllers, :views, :helpers].each do |sub|
75
+ desc "Run the specs under spec/#{sub}"
76
+ Spec::Rake::SpecTask.new(sub) do |t|
77
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
78
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
79
+ end
80
+ end
81
+
82
+ desc "Run the Cucumber features"
83
+ Cucumber::Rake::Task.new(:integration) do |t|
84
+ t.fork = true
85
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
86
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
87
+ t.profile = "default"
88
+ end
89
+
90
+ # Setup specs for stats
91
+ task :statsetup do
92
+ require 'code_statistics'
93
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
94
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
95
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
96
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
97
+ ::CodeStatistics::TEST_TYPES << "Model specs"
98
+ ::CodeStatistics::TEST_TYPES << "View specs"
99
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
100
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
101
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
102
+ end
103
+
104
+ namespace :db do
105
+ namespace :fixtures do
106
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
107
+ task :load => :environment do
108
+ require 'active_record/fixtures'
109
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
110
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
111
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ desc 'Generate documentation for the smarty_pants_filter extension.'
119
+ Rake::RDocTask.new(:rdoc) do |rdoc|
120
+ rdoc.rdoc_dir = 'rdoc'
121
+ rdoc.title = 'SmartyPantsFilterExtension'
122
+ rdoc.options << '--line-numbers' << '--inline-source'
123
+ rdoc.rdoc_files.include('README')
124
+ rdoc.rdoc_files.include('lib/**/*.rb')
125
+ end
126
+
127
+ # For extensions that are in transition
128
+ desc 'Test the smarty_pants_filter extension.'
129
+ Rake::TestTask.new(:test) do |t|
130
+ t.libs << 'lib'
131
+ t.pattern = 'test/**/*_test.rb'
132
+ t.verbose = true
133
+ end
134
+
135
+ # Load any custom rakefiles for extension
136
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,2 @@
1
+ module RadiantSmartyPantsFilterExtension
2
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantSmartyPantsFilterExtension
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ class SmartyPantsFilter < TextFilter
2
+ filter_name "SmartyPants"
3
+ description_file File.dirname(__FILE__) + "/../smartypants.html"
4
+ def filter(text)
5
+ RubyPants.new(text).to_html
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module SmartyPantsTags
2
+ include Radiant::Taggable
3
+
4
+ desc %{
5
+ Filters its contents with the SmartyPants filter.
6
+
7
+ *Usage:*
8
+
9
+ <pre><code><r:smarty_pants>"A revolutionary quotation."</r:smarty_pants></code></pre>
10
+
11
+ produces
12
+
13
+ <pre><code>&#8220;A revolutionary quotation.&#8221;</code></pre>
14
+ }
15
+ tag 'smarty_pants' do |tag|
16
+ SmartyPantsFilter.filter(tag.expand)
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :smarty_pants_filter do
4
+
5
+ desc "Runs the migration of the SmartyPants Filter extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ SmartyPantsFilterExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ SmartyPantsFilterExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the SmartyPants 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[SmartyPantsFilterExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
19
+ path = file.sub(SmartyPantsFilterExtension.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
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-smarty_pants_filter-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-smarty_pants_filter-extension"
7
+ s.version = RadiantSmartyPantsFilterExtension::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 "rubypants", "~> 0.2.0"
25
+
26
+ s.post_install_message = %{
27
+ Add this to your radiant project with:
28
+ config.gem "radiant-smarty_pants_filter-extension", :version => "~> #{RadiantSmartyPantsFilterExtension::VERSION}"
29
+ }
30
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'rubypants'
3
+ rescue LoadError
4
+ # If rubypants gem is not available, use packaged version
5
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/vendor/rubypants"
6
+ retry
7
+ end
8
+
9
+ class SmartyPantsFilterExtension < Radiant::Extension
10
+ version "1.0"
11
+ description "Allows you to compose page parts or snippets using the SmartyPants text filter."
12
+ url "http://daringfireball.net/projects/smartypants/"
13
+
14
+ def activate
15
+ SmartyPantsFilter
16
+ Page.send :include, SmartyPantsTags
17
+ end
18
+ end
data/smartypants.html ADDED
@@ -0,0 +1,47 @@
1
+ <p><a href="http://daringfireball.net/projects/smartypants/" target="_blank">SmartyPants</a>
2
+ is a simple text filter that will curl quotes and insert &#8220;smart&#8221;
3
+ punctuation. This is extremely useful if you prefer to compose documents using
4
+ standard HTML, but don&#8217;t want to worry about quotes and punctuation.</p>
5
+
6
+ <table id="filter-reference-table">
7
+ <thead>
8
+ <tr>
9
+ <th>To see this:</th>
10
+ <th>Type this:</th>
11
+ <tr>
12
+ </thead>
13
+ <tbody>
14
+ <tr>
15
+ <td>&#8216;single quotes&#8217;</td>
16
+ <td><pre>'single quotes'</pre></td>
17
+ </tr>
18
+ <tr>
19
+ <td>&#8220;double quotes&#8221;</td>
20
+ <td><pre>"double quotes"</pre></td>
21
+ </tr>
22
+ <tr>
23
+ <td>&#8220;backtick quotes&#8221;</td>
24
+ <td><pre>``backtick quotes''</pre></td>
25
+ </tr>
26
+ <tr>
27
+ <td>John&#8217;s apostrophe</td>
28
+ <td><pre>John's apostrophe</pre></td>
29
+ </tr>
30
+ <tr>
31
+ <td>just an &#8211; en-dash</td>
32
+ <td><pre>just an -- en-dash</pre></td>
33
+ </tr>
34
+ <tr>
35
+ <td>just an&#8212;em-dash</td>
36
+ <td><pre>just an---em-dash</pre></td>
37
+ </tr>
38
+ <tr>
39
+ <td>ellipsis&#8230;</td>
40
+ <td><pre>ellipsis...</pre></td>
41
+ </tr>
42
+ </tbody>
43
+ </table>
44
+
45
+ <p>SmartyPants ignores characters within <code>&lt;pre&gt;</code>,
46
+ <code>&lt;code&gt;</code>, <code>&lt;kbd&gt;</code>, or
47
+ <code>&lt;script&gt;</code> tag blocks.</p>
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SmartyPantsFilter do
4
+ it "should be named SmartyPants" do
5
+ SmartyPantsFilter.filter_name.should == "SmartyPants"
6
+ end
7
+
8
+ it "should filter text with quotes into smart quotes" do
9
+ SmartyPantsFilter.filter("<h1 class=\"headline\">Radiant's \"filters\" rock!</h1>").should ==
10
+ "<h1 class=\"headline\">Radiant&#8217;s &#8220;filters&#8221; rock!</h1>"
11
+ end
12
+ end
13
+
14
+ describe "<r:smarty_pants>" do
15
+ dataset :pages
16
+ it "should filter its contents with SmartyPants" do
17
+ pages(:home).should render('<r:smarty_pants>"A revolutionary quotation."</r:smarty_pants>').as("&#8220;A revolutionary quotation.&#8221;")
18
+ end
19
+ 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,14 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class SmartyPantsFilterTest < Test::Unit::TestCase
4
+
5
+ def test_filter_name
6
+ assert_equal 'SmartyPants', SmartyPantsFilter.filter_name
7
+ end
8
+
9
+ def test_filter
10
+ assert_equal "<h1 class=\"headline\">Radiant&#8217;s &#8220;filters&#8221; rock!</h1>",
11
+ SmartyPantsFilter.filter("<h1 class=\"headline\">Radiant's \"filters\" rock!</h1>")
12
+ end
13
+
14
+ end
@@ -0,0 +1,114 @@
1
+ = RubyPants -- SmartyPants ported to Ruby
2
+
3
+ Ported by Christian Neukirchen <mailto:chneukirchen@gmail.com>
4
+ Copyright (C) 2004 Christian Neukirchen
5
+
6
+ Incooporates ideas, comments and documentation by Chad Miller
7
+ Copyright (C) 2004 Chad Miller
8
+
9
+ Original SmartyPants by John Gruber
10
+ Copyright (C) 2003 John Gruber
11
+
12
+
13
+ == RubyPants
14
+
15
+ RubyPants is a Ruby port of the smart-quotes library SmartyPants.
16
+
17
+ The original "SmartyPants" is a free web publishing plug-in for
18
+ Movable Type, Blosxom, and BBEdit that easily translates plain ASCII
19
+ punctuation characters into "smart" typographic punctuation HTML
20
+ entities.
21
+
22
+ See rubypants.rb for more information.
23
+
24
+
25
+ == Incompatibilities
26
+
27
+ RubyPants uses a different API than SmartyPants; it is compatible to
28
+ Red- and BlueCloth. Usually, you call RubyPants like this:
29
+
30
+ nicehtml = RubyPants.new(uglyhtml, options).to_html
31
+
32
+ where +options+ is an Array of Integers and/or Symbols (if you don't
33
+ pass any options, RubyPants will use <tt>[2]</tt> as default.)
34
+
35
+ *Note*:: This is incompatible to SmartyPants, which uses <tt>[1]</tt>
36
+ for default.
37
+
38
+ The exact meaning of numbers and symbols is documented at RubyPants#new.
39
+
40
+
41
+ == SmartyPants license:
42
+
43
+ Copyright (c) 2003 John Gruber
44
+ (http://daringfireball.net)
45
+ All rights reserved.
46
+
47
+ Redistribution and use in source and binary forms, with or without
48
+ modification, are permitted provided that the following conditions
49
+ are met:
50
+
51
+ * Redistributions of source code must retain the above copyright
52
+ notice, this list of conditions and the following disclaimer.
53
+
54
+ * Redistributions in binary form must reproduce the above copyright
55
+ notice, this list of conditions and the following disclaimer in
56
+ the documentation and/or other materials provided with the
57
+ distribution.
58
+
59
+ * Neither the name "SmartyPants" nor the names of its contributors
60
+ may be used to endorse or promote products derived from this
61
+ software without specific prior written permission.
62
+
63
+ This software is provided by the copyright holders and contributors
64
+ "as is" and any express or implied warranties, including, but not
65
+ limited to, the implied warranties of merchantability and fitness
66
+ for a particular purpose are disclaimed. In no event shall the
67
+ copyright owner or contributors be liable for any direct, indirect,
68
+ incidental, special, exemplary, or consequential damages (including,
69
+ but not limited to, procurement of substitute goods or services;
70
+ loss of use, data, or profits; or business interruption) however
71
+ caused and on any theory of liability, whether in contract, strict
72
+ liability, or tort (including negligence or otherwise) arising in
73
+ any way out of the use of this software, even if advised of the
74
+ possibility of such damage.
75
+
76
+
77
+ == RubyPants license
78
+
79
+ Copyright (C) 2004 Christian Neukirchen
80
+
81
+ RubyPants is a derivative work of SmartyPants and smartypants.py.
82
+
83
+ Redistribution and use in source and binary forms, with or without
84
+ modification, are permitted provided that the following conditions
85
+ are met:
86
+
87
+ * Redistributions of source code must retain the above copyright
88
+ notice, this list of conditions and the following disclaimer.
89
+
90
+ * Redistributions in binary form must reproduce the above copyright
91
+ notice, this list of conditions and the following disclaimer in
92
+ the documentation and/or other materials provided with the
93
+ distribution.
94
+
95
+ This software is provided by the copyright holders and contributors
96
+ "as is" and any express or implied warranties, including, but not
97
+ limited to, the implied warranties of merchantability and fitness
98
+ for a particular purpose are disclaimed. In no event shall the
99
+ copyright owner or contributors be liable for any direct, indirect,
100
+ incidental, special, exemplary, or consequential damages (including,
101
+ but not limited to, procurement of substitute goods or services;
102
+ loss of use, data, or profits; or business interruption) however
103
+ caused and on any theory of liability, whether in contract, strict
104
+ liability, or tort (including negligence or otherwise) arising in
105
+ any way out of the use of this software, even if advised of the
106
+ possibility of such damage.
107
+
108
+
109
+ == Links
110
+
111
+ John Gruber:: http://daringfireball.net
112
+ SmartyPants:: http://daringfireball.net/projects/smartypants
113
+ Chad Miller:: http://web.chad.org
114
+ Christian Neukirchen:: http://kronavita.de/chris