acts_as_markup 2.0.1 → 2.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/README.rdoc +0 -10
- data/lib/acts_as_markup.rb +51 -2
- data/lib/acts_as_markup/active_record_extension.rb +39 -80
- data/lib/acts_as_markup/version.rb +1 -1
- data/test/acts_as_markup_test.rb +16 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3767dcc2b335c8b237088401fbf8224d7bf97bee
|
4
|
+
data.tar.gz: d13496c1a244d5daf3c2bc0d0417670f3c4aa768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc4ec54b50660d15a82cdb268dacaf7aa79b8be897fed51642c22ba9a2af67853b6c0580dc4396984df18d431c22df501670510e5e48268acc61f17c4b26a262
|
7
|
+
data.tar.gz: fc1e215a75da5da9b2f8dda31abd4d974c71b3535566670164764939128fa5484b73b491c900f15abca3fd76f71a88cd359ca8ca96c0faae4d63883b2cf3e624
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 2.0.2 / 2015-07-21
|
2
|
+
* Plain text variable columns always return strings now
|
3
|
+
* Refactor how we load markup classes to not load ones we aren't using.
|
4
|
+
|
5
|
+
== 2.0.1 / 2014-09-04
|
6
|
+
* Stop extending Object and extend string instead.
|
7
|
+
|
1
8
|
== 2.0.0 / 2014-09-03
|
2
9
|
* Update for latest version of Ruby & Rails
|
3
10
|
|
data/README.rdoc
CHANGED
@@ -123,16 +123,6 @@ The four options currently supported are:
|
|
123
123
|
|
124
124
|
== INSTALL:
|
125
125
|
|
126
|
-
==== Rails 2
|
127
|
-
|
128
|
-
<tt>(sudo) gem install acts_as_markup</tt>
|
129
|
-
|
130
|
-
Add "+acts_as_markup+" to your environment.rb:
|
131
|
-
|
132
|
-
config.gem "acts_as_markup"
|
133
|
-
|
134
|
-
==== Rails 3
|
135
|
-
|
136
126
|
Simply add "+acts_as_markup+" to your Gemfile:
|
137
127
|
|
138
128
|
gem "acts_as_markup"
|
data/lib/acts_as_markup.rb
CHANGED
@@ -30,8 +30,57 @@ module ActsAsMarkup
|
|
30
30
|
mattr_accessor :markdown_library
|
31
31
|
|
32
32
|
# Returns the version string for the library.
|
33
|
-
|
34
|
-
|
33
|
+
class << self
|
34
|
+
def version
|
35
|
+
VERSION
|
36
|
+
end
|
37
|
+
|
38
|
+
def markup_class(markup_name)
|
39
|
+
load_markup_class(markup_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get_markdown_class
|
45
|
+
if ActsAsMarkup::MARKDOWN_LIBS.keys.include? ActsAsMarkup.markdown_library
|
46
|
+
markdown_library_names = ActsAsMarkup::MARKDOWN_LIBS[ActsAsMarkup.markdown_library]
|
47
|
+
require markdown_library_names[:lib_name]
|
48
|
+
require_extensions(markdown_library_names[:lib_name])
|
49
|
+
return markdown_library_names[:class_name].constantize
|
50
|
+
else
|
51
|
+
raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def require_extensions(library)# :nodoc:
|
56
|
+
if ActsAsMarkup::LIBRARY_EXTENSIONS.include? library.to_s
|
57
|
+
require "acts_as_markup/exts/#{library}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def require_library_and_get_class(language)
|
62
|
+
case language
|
63
|
+
when :markdown
|
64
|
+
return get_markdown_class
|
65
|
+
when :textile
|
66
|
+
require 'redcloth'
|
67
|
+
return RedCloth
|
68
|
+
when :rdoc
|
69
|
+
require 'rdoc'
|
70
|
+
require_extensions 'rdoc'
|
71
|
+
return RDocText
|
72
|
+
else
|
73
|
+
return String
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_markup_class(markup_name)
|
78
|
+
if [:markdown, :textile, :rdoc].include?(markup_name.to_sym)
|
79
|
+
require_library_and_get_class(markup_name.to_sym)
|
80
|
+
else
|
81
|
+
raise ActsAsMarkup::UnsupportedMarkupLanguage, "#{markup_name} is not a currently supported markup language."
|
82
|
+
end
|
83
|
+
end
|
35
84
|
end
|
36
85
|
|
37
86
|
end
|
@@ -66,12 +66,13 @@ module ActsAsMarkup
|
|
66
66
|
#
|
67
67
|
def acts_as_markup(options)
|
68
68
|
options.reverse_merge!(:language_column => :markup_language)
|
69
|
-
|
70
|
-
|
69
|
+
|
70
|
+
include InstanceMethods
|
71
|
+
|
71
72
|
unless options[:language].to_sym == :variable
|
72
|
-
define_markup_columns_reader_methods(
|
73
|
+
define_markup_columns_reader_methods(options)
|
73
74
|
else
|
74
|
-
define_variable_markup_columns_reader_methods(
|
75
|
+
define_variable_markup_columns_reader_methods(options)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -101,93 +102,51 @@ module ActsAsMarkup
|
|
101
102
|
options = columns.extract_options!
|
102
103
|
acts_as_markup options.merge(:language => :rdoc, :columns => columns)
|
103
104
|
end
|
104
|
-
|
105
|
-
|
105
|
+
|
106
106
|
private
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
require markdown_library_names[:lib_name]
|
111
|
-
require_extensions(markdown_library_names[:lib_name])
|
112
|
-
return markdown_library_names[:class_name].constantize
|
113
|
-
else
|
114
|
-
raise ActsAsMarkup::UnsportedMarkdownLibrary, "#{ActsAsMarkup.markdown_library} is not currently supported."
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def require_extensions(library)# :nodoc:
|
119
|
-
if ActsAsMarkup::LIBRARY_EXTENSIONS.include? library.to_s
|
120
|
-
require "acts_as_markup/exts/#{library}"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def require_library_and_get_class(language)
|
125
|
-
case language
|
126
|
-
when :markdown
|
127
|
-
return get_markdown_class
|
128
|
-
when :textile
|
129
|
-
require 'redcloth'
|
130
|
-
return RedCloth
|
131
|
-
when :rdoc
|
132
|
-
require 'rdoc'
|
133
|
-
require_extensions 'rdoc'
|
134
|
-
return RDocText
|
135
|
-
else
|
136
|
-
return String
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def load_markup_class(options)
|
141
|
-
case options[:language].to_sym
|
142
|
-
when :markdown, :textile, :rdoc
|
143
|
-
require_library_and_get_class(options[:language].to_sym)
|
144
|
-
when :variable
|
145
|
-
markup_classes = {}
|
146
|
-
[:textile, :rdoc, :markdown].each do |language|
|
147
|
-
markup_classes[language] = require_library_and_get_class(language)
|
148
|
-
end
|
149
|
-
markup_classes
|
150
|
-
else
|
151
|
-
raise ActsAsMarkup::UnsupportedMarkupLanguage, "#{options[:langauge]} is not a currently supported markup language."
|
152
|
-
end
|
153
|
-
end
|
107
|
+
|
108
|
+
def define_markup_columns_reader_methods(options)
|
109
|
+
markup_options = options["#{options[:language]}_options".to_sym] || []
|
154
110
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
instance_variable_get("@#{col}")
|
162
|
-
else
|
163
|
-
instance_variable_set("@#{col}", markup_class.new(self[col].to_s, *markup_options))
|
164
|
-
end
|
111
|
+
options[:columns].each do |col|
|
112
|
+
define_method col do
|
113
|
+
if instance_variable_defined?("@#{col}") && !send("#{col}_changed?")
|
114
|
+
instance_variable_get("@#{col}")
|
115
|
+
else
|
116
|
+
instance_variable_set("@#{col}", markup_class(options[:language]).new(self[col].to_s, *markup_options))
|
165
117
|
end
|
166
118
|
end
|
167
119
|
end
|
120
|
+
end
|
168
121
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
end
|
122
|
+
def define_variable_markup_columns_reader_methods(options)
|
123
|
+
options[:columns].each do |col|
|
124
|
+
define_method col do
|
125
|
+
if instance_variable_defined?("@#{col}")
|
126
|
+
unless send("#{col}_changed?") || send("#{options[:language_column]}_changed?")
|
127
|
+
return instance_variable_get("@#{col}")
|
176
128
|
end
|
177
|
-
instance_variable_set("@#{col}", case send(options[:language_column])
|
178
|
-
when /markdown/i
|
179
|
-
markup_classes[:markdown].new string_for_markup_column(col), *(options[:markdown_options] || [])
|
180
|
-
when /textile/i
|
181
|
-
markup_classes[:textile].new string_for_markup_column(col), *(options[:textile_options] || [])
|
182
|
-
when /rdoc/i
|
183
|
-
markup_classes[:rdoc].new string_for_markup_column(col)
|
184
|
-
else
|
185
|
-
self[col]
|
186
|
-
end)
|
187
129
|
end
|
130
|
+
instance_variable_set("@#{col}", case send(options[:language_column])
|
131
|
+
when /markdown/i
|
132
|
+
markup_class(:markdown).new string_for_markup_column(col), *(options[:markdown_options] || [])
|
133
|
+
when /textile/i
|
134
|
+
markup_class(:textile).new string_for_markup_column(col), *(options[:textile_options] || [])
|
135
|
+
when /rdoc/i
|
136
|
+
markup_class(:rdoc).new string_for_markup_column(col)
|
137
|
+
else
|
138
|
+
String(self[col])
|
139
|
+
end)
|
188
140
|
end
|
189
141
|
end
|
142
|
+
end
|
190
143
|
|
191
144
|
end
|
145
|
+
|
146
|
+
module InstanceMethods
|
147
|
+
def markup_class(markup_name)
|
148
|
+
ActsAsMarkup.markup_class(markup_name)
|
149
|
+
end
|
150
|
+
end
|
192
151
|
end
|
193
152
|
end
|
data/test/acts_as_markup_test.rb
CHANGED
@@ -220,7 +220,6 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
220
220
|
|
221
221
|
teardown do
|
222
222
|
@rdoctext, @rdoc_post = nil
|
223
|
-
Post.delete_all
|
224
223
|
end
|
225
224
|
end
|
226
225
|
|
@@ -237,12 +236,10 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
237
236
|
should "return the original string with a `to_s` method call on the column value" do
|
238
237
|
assert_equal @plain_text, @plain_text_post.body.to_s
|
239
238
|
end
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
# assert_equal @plain_text, @plain_text_post.body.to_html
|
245
|
-
# end
|
239
|
+
|
240
|
+
should "return the original string with a `to_html` method call on the column value" do
|
241
|
+
assert_equal @plain_text, @plain_text_post.body.to_html
|
242
|
+
end
|
246
243
|
|
247
244
|
context "changing value of markup field should return new markup object" do
|
248
245
|
setup do
|
@@ -269,7 +266,6 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
269
266
|
end
|
270
267
|
end
|
271
268
|
|
272
|
-
|
273
269
|
teardown do
|
274
270
|
VariablePost.delete_all
|
275
271
|
end
|
@@ -304,6 +300,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
304
300
|
|
305
301
|
context 'with textile' do
|
306
302
|
setup do
|
303
|
+
ActsAsMarkup.markup_class(:textile)
|
307
304
|
class ::Post < ActiveRecord::Base
|
308
305
|
acts_as_textile :body
|
309
306
|
end
|
@@ -334,6 +331,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
334
331
|
|
335
332
|
context 'with RDoc' do
|
336
333
|
setup do
|
334
|
+
ActsAsMarkup.markup_class(:rdoc)
|
337
335
|
class ::Post < ActiveRecord::Base
|
338
336
|
acts_as_rdoc :body
|
339
337
|
end
|
@@ -365,6 +363,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
365
363
|
context 'with RDiscount Markdown' do
|
366
364
|
setup do
|
367
365
|
ActsAsMarkup.markdown_library = :rdiscount
|
366
|
+
ActsAsMarkup.markup_class(:markdown)
|
368
367
|
class ::Post < ActiveRecord::Base
|
369
368
|
acts_as_markdown :body
|
370
369
|
end
|
@@ -396,6 +395,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
396
395
|
context 'with BlueCloth Markdown' do
|
397
396
|
setup do
|
398
397
|
ActsAsMarkup.markdown_library = :bluecloth
|
398
|
+
ActsAsMarkup.markup_class(:markdown)
|
399
399
|
class ::Post < ActiveRecord::Base
|
400
400
|
acts_as_markdown :body
|
401
401
|
end
|
@@ -427,6 +427,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
427
427
|
context 'with Ruby PEG Markdown' do
|
428
428
|
setup do
|
429
429
|
ActsAsMarkup.markdown_library = :rpeg
|
430
|
+
ActsAsMarkup.markup_class(:markdown)
|
430
431
|
class ::Post < ActiveRecord::Base
|
431
432
|
acts_as_markdown :body
|
432
433
|
end
|
@@ -446,7 +447,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
446
447
|
end
|
447
448
|
|
448
449
|
should "have a PEGMarkdown object returned for the column value" do
|
449
|
-
assert_kind_of PEGMarkdown, @post.body
|
450
|
+
assert_kind_of ::PEGMarkdown, @post.body
|
450
451
|
end
|
451
452
|
|
452
453
|
teardown do
|
@@ -458,6 +459,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
458
459
|
context 'with Maruku Markdown' do
|
459
460
|
setup do
|
460
461
|
ActsAsMarkup.markdown_library = :maruku
|
462
|
+
ActsAsMarkup.markup_class(:markdown)
|
461
463
|
class ::Post < ActiveRecord::Base
|
462
464
|
acts_as_markdown :body
|
463
465
|
end
|
@@ -490,6 +492,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
490
492
|
context 'with Redcarpet Markdown' do
|
491
493
|
setup do
|
492
494
|
ActsAsMarkup.markdown_library = :redcarpet
|
495
|
+
ActsAsMarkup.markup_class(:markdown)
|
493
496
|
class ::Post < ActiveRecord::Base
|
494
497
|
acts_as_markdown :body
|
495
498
|
end
|
@@ -509,7 +512,7 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
509
512
|
end
|
510
513
|
|
511
514
|
should "have a Maruku object returned for the column value" do
|
512
|
-
assert_kind_of RedcarpetText, @post.body
|
515
|
+
assert_kind_of ::RedcarpetText, @post.body
|
513
516
|
end
|
514
517
|
|
515
518
|
teardown do
|
@@ -522,20 +525,16 @@ class ActsAsMarkupTest < ActsAsMarkupTestCase
|
|
522
525
|
context 'acts_as_markup with bad language name' do
|
523
526
|
should 'raise exception when a non-supported language is passed to acts_as_markup' do
|
524
527
|
assert_raise ActsAsMarkup::UnsupportedMarkupLanguage do
|
525
|
-
|
526
|
-
acts_as_markup :language => :fake, :columns => [:body]
|
527
|
-
end
|
528
|
+
ActsAsMarkup.markup_class(:fake)
|
528
529
|
end
|
529
530
|
end
|
530
531
|
end
|
531
532
|
|
532
533
|
context 'acts_as_markup with bad markdown library' do
|
533
534
|
should 'raise exception when a non-supported library is set as the markdown library attribute on ActsAsMarkup' do
|
535
|
+
ActsAsMarkup.markdown_library = :fake
|
534
536
|
assert_raise ActsAsMarkup::UnsportedMarkdownLibrary do
|
535
|
-
ActsAsMarkup.
|
536
|
-
class ::Post < ActiveRecord::Base
|
537
|
-
acts_as_markup :language => :markdown, :columns => [:body]
|
538
|
-
end
|
537
|
+
ActsAsMarkup.markup_class(:markdown)
|
539
538
|
end
|
540
539
|
end
|
541
540
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Landau
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
QHjym4e4y/FmXBJjpO/TtRoYd8a5YTCaOsML7M/nb/XrArvE3l5JaNEXkhH/nGs7
|
30
30
|
wR9huisTMlESX3ReGKU=
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: activesupport
|
@@ -278,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
278
|
version: '0'
|
279
279
|
requirements: []
|
280
280
|
rubyforge_project:
|
281
|
-
rubygems_version: 2.
|
281
|
+
rubygems_version: 2.4.5
|
282
282
|
signing_key:
|
283
283
|
specification_version: 4
|
284
284
|
summary: Represent ActiveRecord Markdown, Textile, RDoc columns as Markdown, Textile,
|