wikitext 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,10 +16,10 @@ require 'wikitext/string'
16
16
 
17
17
  module Wikitext
18
18
  class TemplateHandler
19
-
20
- # tested with Rails 2.2.2: the API has now changed so many times that I'm no longer going to support older versions of Rails
21
19
  def self.call template
22
20
  'template.source.w'
23
21
  end
24
22
  end
25
23
  end
24
+
25
+ ActionView::Template.register_template_handler :wikitext, Wikitext::TemplateHandler
@@ -13,5 +13,5 @@
13
13
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
14
 
15
15
  module Wikitext
16
- VERSION = '1.3.0'
16
+ VERSION = '1.3.1'
17
17
  end # module Wikitext
@@ -0,0 +1,78 @@
1
+ # Copyright 2007-2009 Wincent Colaiuta
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
+
15
+ require 'pathname'
16
+ require 'rubygems'
17
+ require 'spec'
18
+
19
+ # allow indenting of multiline spec data for better readability
20
+ # but must dedent it before actually doing the comparison
21
+ def dedent spaces, string = nil
22
+ if spaces.kind_of? String
23
+ if not string.nil?
24
+ raise 'When first argument is a String, second argument must be nil'
25
+ else
26
+ # default use: single String parameter, dedent by 6
27
+ string = spaces
28
+ spaces = 6
29
+ end
30
+ elsif spaces.kind_of? Integer
31
+ if string.nil? or not string.kind_of?(String)
32
+ raise 'When first argument is a number, second must be a String'
33
+ end
34
+ else
35
+ raise 'Invalid argument'
36
+ end
37
+ string.each do |line|
38
+ if not line =~ /\A {#{spaces.to_i}}/
39
+ raise "Underlength indent for line: #{line.inspect}"
40
+ end
41
+ end
42
+ string.gsub /^ {#{spaces.to_i}}/, ''
43
+ end
44
+
45
+ module Wikitext
46
+ if not const_defined? 'BASEDIR'
47
+ # prepend the local "ext" directory to search path if not already present
48
+ BASEDIR = Pathname.new(__FILE__).dirname + '..'
49
+ extdir = (BASEDIR + 'ext').realpath
50
+ libdir = (BASEDIR + 'lib').realpath
51
+ normalized = $:.collect { |path| Pathname.new(path).realpath rescue path }
52
+ [libdir, extdir].each { |d| $:.unshift(d) unless normalized.include?(d) }
53
+ end
54
+ end # module Wikitext
55
+
56
+ module UTF8
57
+ if not const_defined? 'Invalid'
58
+ module Invalid
59
+ TWO_BYTES_MISSING_SECOND_BYTE = [0b11011111].pack('C*')
60
+ TWO_BYTES_MALFORMED_SECOND_BYTE = [0b11011111, 0b00001111].pack('C*') # should be 10......
61
+ OVERLONG = [0b11000000, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
62
+ OVERLONG_ALT = [0b11000001, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
63
+ THREE_BYTES_MISSING_SECOND_BYTE = [0b11100000].pack('C*')
64
+ THREE_BYTES_MISSING_THIRD_BYTE = [0b11100000, 0b10000000].pack('C*')
65
+ THREE_BYTES_MALFORMED_SECOND_BYTE = [0b11100000, 0b00001111, 0b10000000].pack('C*') # should be 10......
66
+ THREE_BYTES_MALFORMED_THIRD_BYTE = [0b11100000, 0b10000000, 0b00001111].pack('C*') # should be 10......
67
+ FOUR_BYTES_MISSING_SECOND_BYTE = [0b11110000].pack('C*')
68
+ FOUR_BYTES_MISSING_THIRD_BYTE = [0b11110000, 0x10111111].pack('C*')
69
+ FOUR_BYTES_MISSING_FOURTH_BYTE = [0b11110000, 0x10111111, 0x10111111].pack('C*')
70
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
71
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
72
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT2 = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
73
+ UNEXPECTED_BYTE = [0b11111000].pack('C*')
74
+ end # module Invalid
75
+ end
76
+ end # module UTF8
77
+
78
+ require 'wikitext'
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/version'
18
+ require 'fileutils'
19
+ require 'pathname'
20
+ require 'wopen3'
21
+ require 'ostruct'
22
+
23
+ module RailsSpecs
24
+ TRASH_PATH = Pathname.new(__FILE__).dirname + 'trash'
25
+ CLONE_PATH = TRASH_PATH + 'rails.git'
26
+ RAILS_PATH = CLONE_PATH + 'railties' + 'bin' + 'rails'
27
+ EDGE_APP_PATH = TRASH_PATH + 'edge-app'
28
+
29
+ def run cmd, *args
30
+ result = OpenStruct.new
31
+ result.stdout = ''
32
+ result.stderr = ''
33
+ Wopen3.popen3(*([cmd] + args)) do |stdin, stdout, stderr|
34
+ threads = []
35
+ threads << Thread.new(stdout) do |out|
36
+ out.each { |line| result.stdout << line }
37
+ end
38
+ threads << Thread.new(stderr) do |err|
39
+ err.each { |line| result.stderr << line }
40
+ end
41
+ threads.each { |thread| thread.join }
42
+ end
43
+ status = $?.exitstatus
44
+ if status != 0
45
+ command_string = ([cmd] + args).join(' ')
46
+ puts "*** COMMAND #{command_string} EXITED WITH NON-ZERO EXIT STATUS (#{status})"
47
+ puts "*** STDOUT FOR COMMAND #{command_string}:", result.stdout
48
+ puts "*** STDERR FOR COMMAND #{command_string}:", result.stderr
49
+ raise "non-zero exit status (#{status}) for '#{cmd}'"
50
+ end
51
+ result
52
+ end
53
+
54
+ def clone
55
+ if File.exist? CLONE_PATH
56
+ FileUtils.cd CLONE_PATH do
57
+ run 'git', 'fetch'
58
+ end
59
+ else
60
+ run 'git', 'clone', 'git://github.com/rails/rails.git', CLONE_PATH
61
+ end
62
+ end
63
+
64
+ def app_path version
65
+ TRASH_PATH + "#{version}-app"
66
+ end
67
+
68
+ def create_base_app_and_symlinks app, &block
69
+ clone
70
+ FileUtils.rm_r(app) if File.exist?(app)
71
+ yield
72
+ run 'ruby', RAILS_PATH, app
73
+ vendor = app + 'vendor'
74
+ gems = vendor + 'gems'
75
+ FileUtils.cd vendor do
76
+ FileUtils.ln_s '../../rails.git', 'rails'
77
+ end
78
+ FileUtils.mkdir gems
79
+ FileUtils.cd gems do
80
+ FileUtils.ln_s '../../../../..', "wikitext-#{Wikitext::VERSION}"
81
+ end
82
+ end
83
+
84
+ def create_release_app version
85
+ create_base_app_and_symlinks app_path(version) do
86
+ FileUtils.cd CLONE_PATH do
87
+ run 'git', 'checkout', "v#{version}"
88
+ run 'git', 'clean', '-f'
89
+ end
90
+ end
91
+ end
92
+
93
+ def insert text, after, infile
94
+ output = []
95
+ found = false
96
+ File.read(infile).split("\n").each do |line|
97
+ output << line
98
+ if found == false && line =~ /#{Regexp.escape(after)}/
99
+ found = true
100
+ output << text
101
+ end
102
+ end
103
+ File.open(infile, 'wb') { |f| f.write(output.join("\n")) }
104
+ raise "text '#{after}' not found" unless found
105
+ end
106
+
107
+ def add_text_to_initializer text, infile
108
+ insert text, 'Rails::Initializer.run do', infile
109
+ end
110
+
111
+ def create_controller app
112
+ File.open(app + 'app' + 'controllers' + 'wiki_controller.rb', 'w') do |f|
113
+ f.write 'class WikiController < ApplicationController; end'
114
+ end
115
+ end
116
+
117
+ def create_template app
118
+ template_dir = app + 'app' + 'views' + 'wiki'
119
+ FileUtils.mkdir template_dir
120
+ File.open(template_dir + 'index.html.wikitext', 'w') do |f|
121
+ f.write '* hello, world!'
122
+ end
123
+ end
124
+
125
+ def create_test app
126
+ # integration tests won't run without a schema.rb
127
+ FileUtils.touch app + 'db' + 'schema.rb'
128
+
129
+ File.open(app + 'test' + 'integration' + 'wiki_test.rb', 'w') do |f|
130
+ f.write <<'TEST'
131
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
132
+
133
+ class WikiTest < ActionController::IntegrationTest
134
+ def test_wiki_index
135
+ get "/wiki"
136
+ assert_response :success
137
+ assert_template "wiki/index"
138
+ assert_select 'ul>li', 'hello, world!'
139
+ end
140
+ end
141
+ TEST
142
+ end
143
+ end
144
+
145
+ def create_edge_app
146
+ create_base_app_and_symlinks EDGE_APP_PATH do
147
+ FileUtils.cd CLONE_PATH do
148
+ run 'git', 'checkout', 'master'
149
+ run 'git', 'merge', 'origin/master'
150
+ run 'git', 'clean', '-f'
151
+ end
152
+ end
153
+ end
154
+
155
+ def update_environment app
156
+ environment = app + 'config' + 'environment.rb'
157
+ add_text_to_initializer " config.gem 'wikitext', :version => '#{Wikitext::VERSION}'", environment
158
+ FileUtils.cd app do
159
+ run 'rake', 'gems:refresh_specs'
160
+ end
161
+ end
162
+
163
+ def setup_release_app version
164
+ create_release_app version
165
+ path = app_path(version)
166
+ update_environment path
167
+ create_controller path
168
+ create_template path
169
+ create_test path
170
+ end
171
+
172
+ def setup_edge_app
173
+ create_edge_app
174
+ update_environment EDGE_APP_PATH
175
+ create_controller EDGE_APP_PATH
176
+ create_template EDGE_APP_PATH
177
+ create_test EDGE_APP_PATH
178
+ end
179
+
180
+ def run_integration_test app
181
+ FileUtils.cd app do
182
+ return run('rake', 'test:integration').stdout
183
+ end
184
+ end
185
+ end # module RailsSpecs
186
+
187
+ describe 'Template handler in Rails 2.2.2' do
188
+ include RailsSpecs
189
+ version = '2.2.2'
190
+
191
+ before(:all) do
192
+ setup_release_app version
193
+ @path = app_path(version)
194
+ end
195
+
196
+ it 'should process the template using the wikitext module' do
197
+ run_integration_test(@path).should =~ /1 tests, 3 assertions, 0 failures, 0 errors/
198
+ end
199
+ end
200
+
201
+ describe 'Template handler in Edge Rails' do
202
+ include RailsSpecs
203
+
204
+ before(:all) do
205
+ setup_edge_app
206
+ @path = RailsSpecs::EDGE_APP_PATH
207
+ end
208
+
209
+ it 'should process the template using the wikitext module' do
210
+ run_integration_test(@path).should =~ /1 tests, 3 assertions, 0 failures, 0 errors/
211
+ end
212
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2007-2008 Wincent Colaiuta
1
+ # Copyright 2007-2009 Wincent Colaiuta
2
2
  # This program is free software: you can redistribute it and/or modify
3
3
  # it under the terms of the GNU General Public License as published by
4
4
  # the Free Software Foundation, either version 3 of the License, or
@@ -43,12 +43,13 @@ def dedent spaces, string = nil
43
43
  end
44
44
 
45
45
  module Wikitext
46
- if not const_defined? 'EXTDIR'
46
+ if not const_defined? 'BASEDIR'
47
47
  # prepend the local "ext" directory to search path if not already present
48
- base = File.join(File.dirname(__FILE__), '..')
49
- EXTDIR = Pathname.new(File.join(base, 'ext')).realpath
48
+ BASEDIR = Pathname.new(__FILE__).dirname + '..'
49
+ extdir = (BASEDIR + 'ext').realpath
50
+ libdir = (BASEDIR + 'lib').realpath
50
51
  normalized = $:.collect { |path| Pathname.new(path).realpath rescue path }
51
- $:.unshift(EXTDIR) unless normalized.include?(EXTDIR)
52
+ [libdir, extdir].each { |d| $:.unshift(d) unless normalized.include?(d) }
52
53
  end
53
54
  end # module Wikitext
54
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikitext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wincent Colaiuta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-04 00:00:00 +01:00
12
+ date: 2009-01-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,6 +22,7 @@ extensions:
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
+ - spec/#spec_helper.rb#
25
26
  - spec/autolinking_spec.rb
26
27
  - spec/blockquote_spec.rb
27
28
  - spec/em_spec.rb
@@ -45,11 +46,13 @@ files:
45
46
  - spec/nowiki_spec.rb
46
47
  - spec/p_spec.rb
47
48
  - spec/pre_spec.rb
49
+ - spec/rails_spec.rb
48
50
  - spec/regressions_spec.rb
49
51
  - spec/spec_helper.rb
50
52
  - spec/strong_em_spec.rb
51
53
  - spec/strong_spec.rb
52
54
  - spec/tokenizing_spec.rb
55
+ - spec/trash
53
56
  - spec/tt_spec.rb
54
57
  - spec/ul_spec.rb
55
58
  - spec/wikitext_spec.rb