mbrao 1.2.3 → 1.3.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +5 -0
- data/doc/ActionView/Template/Handlers/MbraoTemplate.html +87 -20
- data/doc/ActionView/Template/Handlers.html +1 -1
- data/doc/HTML/Pipeline/KramdownFilter.html +1 -1
- data/doc/HTML/Pipeline.html +1 -1
- data/doc/HTML.html +1 -1
- data/doc/Mbrao/Author.html +337 -67
- data/doc/Mbrao/Content.html +1268 -444
- data/doc/Mbrao/ContentPublicInterface.html +24 -20
- data/doc/Mbrao/Exceptions/InvalidDate.html +1 -1
- data/doc/Mbrao/Exceptions/InvalidMetadata.html +1 -1
- data/doc/Mbrao/Exceptions/Parsing.html +1 -1
- data/doc/Mbrao/Exceptions/Rendering.html +1 -1
- data/doc/Mbrao/Exceptions/UnavailableLocalization.html +1 -1
- data/doc/Mbrao/Exceptions/Unimplemented.html +1 -1
- data/doc/Mbrao/Exceptions/UnknownEngine.html +1 -1
- data/doc/Mbrao/Exceptions.html +1 -1
- data/doc/Mbrao/Parser.html +11 -11
- data/doc/Mbrao/ParsingEngines/Base.html +25 -24
- data/doc/Mbrao/ParsingEngines/PlainText.html +17 -16
- data/doc/Mbrao/ParsingEngines.html +1 -1
- data/doc/Mbrao/PublicInterface/ClassMethods.html +312 -19
- data/doc/Mbrao/PublicInterface.html +1 -1
- data/doc/Mbrao/RenderingEngines/Base.html +7 -7
- data/doc/Mbrao/RenderingEngines/HtmlPipeline.html +27 -15
- data/doc/Mbrao/RenderingEngines.html +1 -1
- data/doc/Mbrao/Validations/ClassMethods.html +21 -21
- data/doc/Mbrao/Validations.html +1 -1
- data/doc/Mbrao/Version.html +3 -3
- data/doc/Mbrao.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +86 -62
- data/doc/top-level-namespace.html +1 -1
- data/lib/mbrao/author.rb +18 -4
- data/lib/mbrao/content.rb +93 -44
- data/lib/mbrao/integrations/rails.rb +12 -5
- data/lib/mbrao/parser.rb +23 -0
- data/lib/mbrao/parsing_engines/base.rb +12 -11
- data/lib/mbrao/parsing_engines/plain_text.rb +29 -23
- data/lib/mbrao/rendering_engines/base.rb +4 -4
- data/lib/mbrao/rendering_engines/html_pipeline.rb +7 -2
- data/lib/mbrao/version.rb +2 -2
- data/spec/mbrao/author_spec.rb +32 -16
- data/spec/mbrao/content_spec.rb +144 -85
- data/spec/mbrao/integrations/rails_spec.rb +14 -0
- data/spec/mbrao/parser_spec.rb +19 -19
- data/spec/mbrao/parsing_engines/base_spec.rb +12 -12
- data/spec/mbrao/parsing_engines/plain_text_spec.rb +21 -21
- data/spec/mbrao/rendering_engines/base_spec.rb +2 -2
- data/spec/mbrao/rendering_engines/html_pipeline_spec.rb +31 -31
- metadata +2 -2
data/spec/mbrao/content_spec.rb
CHANGED
@@ -7,39 +7,39 @@
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
9
|
describe Mbrao::Content do
|
10
|
-
|
10
|
+
subject { Mbrao::Content.new("UID") }
|
11
11
|
|
12
12
|
describe "#initialize" do
|
13
13
|
it "store the uid" do
|
14
|
-
|
15
|
-
expect(
|
14
|
+
subject = Mbrao::Content.new("SAMPLE")
|
15
|
+
expect(subject.uid).to eq("SAMPLE")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#locales=" do
|
20
20
|
it "correctly assign a string, a symbol or an array" do
|
21
|
-
|
22
|
-
expect(
|
23
|
-
|
24
|
-
expect(
|
25
|
-
|
26
|
-
expect(
|
21
|
+
subject.locales = :it
|
22
|
+
expect(subject.locales).to eq(["it"])
|
23
|
+
subject.locales = "en"
|
24
|
+
expect(subject.locales).to eq(["en"])
|
25
|
+
subject.locales = ["en", [:it, :es]]
|
26
|
+
expect(subject.locales).to eq(["en", "it", "es"])
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
shared_examples_for("localized setter") do |attribute|
|
31
31
|
it "should assign a single string" do
|
32
|
-
|
33
|
-
expect(
|
34
|
-
|
35
|
-
expect(
|
36
|
-
|
37
|
-
expect(
|
32
|
+
subject.send("#{attribute}=", "ABC")
|
33
|
+
expect(subject.send(attribute)).to eq("ABC")
|
34
|
+
subject.send("#{attribute}=", 1)
|
35
|
+
expect(subject.send(attribute)).to eq("1")
|
36
|
+
subject.send("#{attribute}=", nil)
|
37
|
+
expect(subject.send(attribute)).to eq("")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should assign a string with locales and sanitized entries" do
|
41
|
-
|
42
|
-
value =
|
41
|
+
subject.send("#{attribute}=", {en: nil, es: "ABC", it: 1})
|
42
|
+
value = subject.send(attribute)
|
43
43
|
expect(value).to be_a(::HashWithIndifferentAccess)
|
44
44
|
expect(value["en"]).to eq("")
|
45
45
|
expect(value[:es]).to eq("ABC")
|
@@ -49,80 +49,80 @@ describe Mbrao::Content do
|
|
49
49
|
|
50
50
|
shared_examples_for("localized getter") do |attribute, v1, v2|
|
51
51
|
it "should raise an exception if not available for that locale" do
|
52
|
-
|
53
|
-
|
54
|
-
expect {
|
55
|
-
expect {
|
52
|
+
subject.locales = [:en, :it, :es]
|
53
|
+
subject.send("#{attribute}=", v1)
|
54
|
+
expect { subject.send("get_#{attribute}", [:de, :it]) }.not_to raise_error
|
55
|
+
expect { subject.send("get_#{attribute}", [:de]) }.to raise_error(Mbrao::Exceptions::UnavailableLocalization)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should return the attribute itself if not localized" do
|
59
|
-
|
60
|
-
|
61
|
-
expect(
|
59
|
+
subject.locales = [:en, :it, :es]
|
60
|
+
subject.send("#{attribute}=", v1)
|
61
|
+
expect(subject.send("get_#{attribute}", [:de, :it])).to eq(v1)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should return the default locale if no locales are specified" do
|
65
65
|
Mbrao::Parser.locale = :it
|
66
|
-
|
67
|
-
expect(
|
66
|
+
subject.send("#{attribute}=", {en: v1, it: v2})
|
67
|
+
expect(subject.send("get_#{attribute}")).to eq(v2)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should return only the subset of valid and request locales" do
|
71
71
|
Mbrao::Parser.locale = :it
|
72
|
-
|
72
|
+
subject.send("#{attribute}=", {en: v1, it: v2, de: v1, es: v2})
|
73
73
|
|
74
|
-
value =
|
74
|
+
value = subject.send("get_#{attribute}", [:de, :es])
|
75
75
|
expect(value).to be_a(::HashWithIndifferentAccess)
|
76
76
|
expect(value.keys).to eq(["de", "es"])
|
77
77
|
|
78
|
-
value =
|
78
|
+
value = subject.send("get_#{attribute}", [:it, :de, :pt, :fr])
|
79
79
|
expect(value.keys.sort).to eq(["de", "it"])
|
80
80
|
|
81
|
-
|
82
|
-
value =
|
81
|
+
subject.locales = [:en, :it, :es]
|
82
|
+
value = subject.send("get_#{attribute}", "*")
|
83
83
|
expect(value.keys.sort).to eq(["de", "en", "es", "it"])
|
84
84
|
|
85
|
-
|
86
|
-
value =
|
85
|
+
subject.send("#{attribute}=", {en: v1, "it,es" => v2, " de, fr " => v1})
|
86
|
+
value = subject.send("get_#{attribute}", [:it, :fr])
|
87
87
|
expect(value.keys.sort).to eq(["fr", "it"])
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
shared_examples_for("date setter") do |attribute|
|
92
92
|
it "should correctly parse a datetime classes" do
|
93
|
-
|
94
|
-
value =
|
93
|
+
subject.send("#{attribute}=", Date.civil(2012, 8, 8))
|
94
|
+
value = subject.send(attribute)
|
95
95
|
expect(value).to be_a(DateTime)
|
96
96
|
expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T000000+0000")
|
97
97
|
|
98
|
-
|
99
|
-
value =
|
98
|
+
subject.send("#{attribute}=", DateTime.civil(2012, 8, 8, 11, 30, 45))
|
99
|
+
value = subject.send(attribute)
|
100
100
|
expect(value).to be_a(DateTime)
|
101
101
|
expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T113045+0000")
|
102
102
|
|
103
103
|
Time.zone = 'Europe/Rome'
|
104
104
|
date = Time.at(1344421800)
|
105
|
-
|
106
|
-
value =
|
105
|
+
subject.send("#{attribute}=", date)
|
106
|
+
value = subject.send(attribute)
|
107
107
|
expect(value).to be_a(DateTime)
|
108
108
|
expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should correctly parse a timestamp" do
|
112
|
-
|
113
|
-
value =
|
112
|
+
subject.send("#{attribute}=", 1344421800)
|
113
|
+
value = subject.send(attribute)
|
114
114
|
expect(value).to be_a(DateTime)
|
115
115
|
expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should try to parse everything else as a ISO8601 format" do
|
119
|
-
|
120
|
-
value =
|
119
|
+
subject.send("#{attribute}=", "20120808T083000-0200")
|
120
|
+
value = subject.send(attribute)
|
121
121
|
expect(value).to be_a(DateTime)
|
122
122
|
expect(value.strftime("%Y%m%dT%H%M%S%z")).to eq("20120808T103000+0000")
|
123
123
|
|
124
|
-
expect {
|
125
|
-
expect {
|
124
|
+
expect { subject.send("#{attribute}=", "ABC") }.to raise_error(Mbrao::Exceptions::InvalidDate)
|
125
|
+
expect { subject.send("#{attribute}=", []) }.to raise_error(Mbrao::Exceptions::InvalidDate)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -132,31 +132,38 @@ describe Mbrao::Content do
|
|
132
132
|
|
133
133
|
describe "#body=" do
|
134
134
|
it "should set the content as string" do
|
135
|
-
|
136
|
-
expect(
|
137
|
-
|
138
|
-
expect(
|
139
|
-
|
140
|
-
expect(
|
135
|
+
subject.body = "A"
|
136
|
+
expect(subject.body).to eq("A")
|
137
|
+
subject.body = 1
|
138
|
+
expect(subject.body).to eq("1")
|
139
|
+
subject.body = nil
|
140
|
+
expect(subject.body).to eq("")
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
describe "#tags=" do
|
145
145
|
it "should assign a single value" do
|
146
|
-
|
147
|
-
expect(
|
148
|
-
|
149
|
-
expect(
|
146
|
+
subject.tags = "ABC"
|
147
|
+
expect(subject.tags).to eq(["ABC"])
|
148
|
+
subject.tags = ["ABC", [1, nil]]
|
149
|
+
expect(subject.tags).to eq(["ABC", "1"])
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should assign values with locales and sanitized entries" do
|
153
|
-
|
154
|
-
value =
|
153
|
+
subject.tags = {en: nil, es: "ABC", it: [1, [2, 3]]}
|
154
|
+
value = subject.tags
|
155
155
|
expect(value).to be_a(::HashWithIndifferentAccess)
|
156
156
|
expect(value["en"]).to eq([])
|
157
157
|
expect(value[:es]).to eq(["ABC"])
|
158
158
|
expect(value["it"]).to eq(["1", "2", "3"])
|
159
159
|
end
|
160
|
+
|
161
|
+
it "should split, flatten and uniquize tags" do
|
162
|
+
subject.tags = ["1", ["2", "3"], "3, 4,5"]
|
163
|
+
expect(subject.tags).to eq(["1","2","3","4","5"])
|
164
|
+
subject.tags = "1,2,3,4,5"
|
165
|
+
expect(subject.tags).to eq(["1","2","3","4","5"])
|
166
|
+
end
|
160
167
|
end
|
161
168
|
|
162
169
|
describe "#more=" do
|
@@ -166,26 +173,26 @@ describe Mbrao::Content do
|
|
166
173
|
describe "#author=" do
|
167
174
|
it "should assign an existing author" do
|
168
175
|
author = ::Mbrao::Author.new("NAME")
|
169
|
-
|
170
|
-
expect(
|
176
|
+
subject.author = author
|
177
|
+
expect(subject.author).to be(author)
|
171
178
|
end
|
172
179
|
|
173
180
|
it "should only assign a name" do
|
174
|
-
|
175
|
-
expect(
|
176
|
-
expect(
|
181
|
+
subject.author = "NAME"
|
182
|
+
expect(subject.author).to be_a(::Mbrao::Author)
|
183
|
+
expect(subject.author.name).to eq("NAME")
|
177
184
|
end
|
178
185
|
|
179
186
|
it "should assign by an hash" do
|
180
|
-
|
181
|
-
expect(
|
182
|
-
expect(
|
183
|
-
expect(
|
184
|
-
expect(
|
185
|
-
expect(
|
186
|
-
expect(
|
187
|
-
expect(
|
188
|
-
expect(
|
187
|
+
subject.author = {name: "NAME", email: "EMAIL@email.com", "website" => "http://WEBSITE.TLD", "image" => "http://IMAGE.TLD", metadata: {a: "b"}, uid: "UID"}
|
188
|
+
expect(subject.author).to be_a(::Mbrao::Author)
|
189
|
+
expect(subject.author.name).to eq("NAME")
|
190
|
+
expect(subject.author.email).to eq("EMAIL@email.com")
|
191
|
+
expect(subject.author.website).to eq("http://WEBSITE.TLD")
|
192
|
+
expect(subject.author.image).to eq("http://IMAGE.TLD")
|
193
|
+
expect(subject.author.metadata).to be_a(::HashWithIndifferentAccess)
|
194
|
+
expect(subject.author.metadata["a"]).to eq("b")
|
195
|
+
expect(subject.author.uid).to eq("UID")
|
189
196
|
end
|
190
197
|
end
|
191
198
|
|
@@ -199,25 +206,25 @@ describe Mbrao::Content do
|
|
199
206
|
|
200
207
|
describe "#metadata=" do
|
201
208
|
it "correctly set a non hash value" do
|
202
|
-
|
203
|
-
expect(
|
204
|
-
expect(
|
209
|
+
subject.metadata = "RAW"
|
210
|
+
expect(subject.metadata).to be_a(::HashWithIndifferentAccess)
|
211
|
+
expect(subject.metadata["raw"]).to eq("RAW")
|
205
212
|
end
|
206
213
|
|
207
214
|
it "correctly set a hash value" do
|
208
|
-
|
209
|
-
expect(
|
210
|
-
expect(
|
215
|
+
subject.metadata = {en: nil, es: "ABC", it: [1, [2, 3]]}
|
216
|
+
expect(subject.metadata).to be_a(::HashWithIndifferentAccess)
|
217
|
+
expect(subject.metadata["es"]).to eq("ABC")
|
211
218
|
end
|
212
219
|
end
|
213
220
|
|
214
221
|
describe "#enabled_for_locales?" do
|
215
222
|
it "correctly check availability for certain locales" do
|
216
|
-
|
217
|
-
expect(
|
218
|
-
expect(
|
219
|
-
expect(
|
220
|
-
expect(
|
223
|
+
subject.locales = [:en, :it]
|
224
|
+
expect(subject.enabled_for_locales?).to be_true
|
225
|
+
expect(subject.enabled_for_locales?(:en)).to be_true
|
226
|
+
expect(subject.enabled_for_locales?(:it, :es)).to be_true
|
227
|
+
expect(subject.enabled_for_locales?(:es, :de)).to be_false
|
221
228
|
end
|
222
229
|
end
|
223
230
|
|
@@ -227,11 +234,11 @@ describe Mbrao::Content do
|
|
227
234
|
|
228
235
|
describe "#get_body" do
|
229
236
|
it "should create a parsing engine and use it for filtering" do
|
230
|
-
|
237
|
+
subject.body = "BODY"
|
231
238
|
engine = ::Mbrao::ParsingEngines::Base.new
|
232
|
-
expect(engine).to receive(:filter_content).with(
|
239
|
+
expect(engine).to receive(:filter_content).with(subject, ["it", "en"])
|
233
240
|
expect(::Mbrao::Parser).to receive(:create_engine).with("ENGINE").and_return(engine)
|
234
|
-
|
241
|
+
subject.get_body(["it", "en"], "ENGINE")
|
235
242
|
end
|
236
243
|
end
|
237
244
|
|
@@ -243,6 +250,58 @@ describe Mbrao::Content do
|
|
243
250
|
it_should_behave_like "localized getter", :more, "ABC", "123"
|
244
251
|
end
|
245
252
|
|
253
|
+
describe "#as_json" do
|
254
|
+
subject {
|
255
|
+
@created_at = DateTime.civil(1984, 7, 7, 11, 30, 0)
|
256
|
+
metadata = {"uid" => "UID", "title" => {it: "IT", en: "EN"}, "author" => "AUTHOR", "tags" => {it: "IT", en: "EN"}, "more" => "MORE", created_at: @created_at, locales: ["it", ["en"]], other: ["OTHER"]}
|
257
|
+
::Mbrao::Content.create(metadata, "BODY")
|
258
|
+
}
|
259
|
+
|
260
|
+
it "should return the content as a JSON hash" do
|
261
|
+
expect(subject.as_json).to eq({
|
262
|
+
"author" => {"uid" => nil, "name" => "AUTHOR", "email" => nil, "website" => nil, "image" => nil, "metadata" => {}},
|
263
|
+
"body" => "BODY",
|
264
|
+
"created_at" => @created_at,
|
265
|
+
"locales" => ["it", "en"],
|
266
|
+
"metadata" => {"other" => ["OTHER"]},
|
267
|
+
"more" => "MORE",
|
268
|
+
"tags" => {"it" => ["IT"], "en"=>["EN"]},
|
269
|
+
"title" => {"it" => "IT", "en" => "EN"},
|
270
|
+
"uid" => "UID",
|
271
|
+
"updated_at" => @created_at
|
272
|
+
})
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should filter out keys if asked to" do
|
276
|
+
expect(subject.as_json(exclude: [:author, :uid])).to eq({
|
277
|
+
"body" => "BODY",
|
278
|
+
"created_at" => @created_at,
|
279
|
+
"locales" => ["it", "en"],
|
280
|
+
"metadata" => {"other" => ["OTHER"]},
|
281
|
+
"more" => "MORE",
|
282
|
+
"tags" => {"it" => ["IT"], "en"=>["EN"]},
|
283
|
+
"title" => {"it" => "IT", "en" => "EN"},
|
284
|
+
"updated_at" => @created_at
|
285
|
+
})
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should filter out empty values if asked to" do
|
289
|
+
subject.author = nil
|
290
|
+
subject.uid = nil
|
291
|
+
|
292
|
+
expect(subject.as_json(exclude_empty: true)).to eq({
|
293
|
+
"body" => "BODY",
|
294
|
+
"created_at" => @created_at,
|
295
|
+
"locales" => ["it", "en"],
|
296
|
+
"metadata" => {"other" => ["OTHER"]},
|
297
|
+
"more" => "MORE",
|
298
|
+
"tags" => {"it" => ["IT"], "en"=>["EN"]},
|
299
|
+
"title" => {"it" => "IT", "en" => "EN"},
|
300
|
+
"updated_at" => @created_at
|
301
|
+
})
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
246
305
|
describe ".create" do
|
247
306
|
it "should return a Content object" do
|
248
307
|
expect(::Mbrao::Content.create(nil, "BODY")).to be_a(::Mbrao::Content)
|
@@ -8,7 +8,14 @@ require "spec_helper"
|
|
8
8
|
require "action_view"
|
9
9
|
require "mbrao/integrations/rails"
|
10
10
|
|
11
|
+
|
11
12
|
describe ActionView::Template::Handlers::MbraoTemplate do
|
13
|
+
class Rails
|
14
|
+
def self.version
|
15
|
+
"3"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
12
19
|
class DummyTemplate
|
13
20
|
def initialize(content)
|
14
21
|
@content = content
|
@@ -34,6 +41,13 @@ describe ActionView::Template::Handlers::MbraoTemplate do
|
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
44
|
+
describe ".register" do
|
45
|
+
it "should register template" do
|
46
|
+
expect(ActionView::Template).to receive(:register_template_handler).with("emt", an_instance_of(ActionView::Template::Handlers::MbraoTemplate))
|
47
|
+
ActionView::Template::Handlers::MbraoTemplate.register
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
37
51
|
describe ".instance" do
|
38
52
|
it "should create a new instance" do
|
39
53
|
expect(ActionView::Template::Handlers::MbraoTemplate.instance).to be_a(ActionView::Template::Handlers::MbraoTemplate)
|
data/spec/mbrao/parser_spec.rb
CHANGED
@@ -59,14 +59,14 @@ describe Mbrao::Parser do
|
|
59
59
|
|
60
60
|
describe ".create_engine" do
|
61
61
|
it "should create an engine via Lazier.find_class" do
|
62
|
-
|
62
|
+
subject = ::Mbrao::ParsingEngines::ScopedParser.new
|
63
63
|
cls = ::Mbrao::ParsingEngines::ScopedParser
|
64
|
-
expect(cls).to receive(:new).exactly(2).and_return(
|
64
|
+
expect(cls).to receive(:new).exactly(2).and_return(subject)
|
65
65
|
|
66
66
|
expect(::Lazier).to receive(:find_class).with(:scoped_parser, "::Mbrao::ParsingEngines::%CLASS%").and_return(cls)
|
67
|
-
expect(::Mbrao::Parser.create_engine(:scoped_parser)).to eq(
|
67
|
+
expect(::Mbrao::Parser.create_engine(:scoped_parser)).to eq(subject)
|
68
68
|
expect(::Lazier).to receive(:find_class).with(:scoped_parser, "::Mbrao::RenderingEngines::%CLASS%").and_return(cls)
|
69
|
-
expect(::Mbrao::Parser.create_engine(:scoped_parser, :rendering)).to eq(
|
69
|
+
expect(::Mbrao::Parser.create_engine(:scoped_parser, :rendering)).to eq(subject)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should raise an exception if the engine class is not found" do
|
@@ -122,12 +122,12 @@ describe Mbrao::Parser do
|
|
122
122
|
|
123
123
|
describe "#parse" do
|
124
124
|
it "should sanitize options" do
|
125
|
-
|
126
|
-
expect(::Mbrao::Parser).to receive(:create_engine).exactly(3).and_return(
|
125
|
+
subject = BlankParser.new
|
126
|
+
expect(::Mbrao::Parser).to receive(:create_engine).exactly(3).and_return(subject)
|
127
127
|
|
128
|
-
expect(
|
129
|
-
expect(
|
130
|
-
expect(
|
128
|
+
expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser})
|
129
|
+
expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => false, "engine" => :blank_parser})
|
130
|
+
expect(subject).to receive(:parse).with("CONTENT", {"metadata" => false, "content" => false, "engine" => :blank_parser})
|
131
131
|
|
132
132
|
::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser})
|
133
133
|
::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser, content: 2})
|
@@ -135,31 +135,31 @@ describe Mbrao::Parser do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should call .create_engine call its #parse method" do
|
138
|
-
|
139
|
-
expect(::Mbrao::Parser).to receive(:create_engine).and_return(
|
138
|
+
subject = BlankParser.new
|
139
|
+
expect(::Mbrao::Parser).to receive(:create_engine).and_return(subject)
|
140
140
|
|
141
|
-
expect(
|
141
|
+
expect(subject).to receive(:parse).with("CONTENT", {"metadata" => true, "content" => true, "engine" => :blank_parser, "other" => "OK"})
|
142
142
|
::Mbrao::Parser.new.parse("CONTENT", {engine: :blank_parser, other: "OK"})
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
146
|
describe "#render" do
|
147
147
|
it "should sanitize options" do
|
148
|
-
|
149
|
-
expect(::Mbrao::Parser).to receive(:create_engine).exactly(2).and_return(
|
148
|
+
subject = Object.new
|
149
|
+
expect(::Mbrao::Parser).to receive(:create_engine).exactly(2).and_return(subject)
|
150
150
|
|
151
|
-
expect(
|
152
|
-
expect(
|
151
|
+
expect(subject).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
|
152
|
+
expect(subject).to receive(:render).with("CONTENT", {"engine" => :html_pipeline}, {content: "OK"})
|
153
153
|
|
154
154
|
::Mbrao::Parser.new.render("CONTENT", {engine: :blank_rendered}, {content: "OK"})
|
155
155
|
::Mbrao::Parser.new.render("CONTENT", {engine: :html_pipeline}, {content: "OK"})
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should call .create_engine call its #parse method" do
|
159
|
-
|
160
|
-
expect(::Mbrao::Parser).to receive(:create_engine).with(:blank_rendered, :rendering).and_return(
|
159
|
+
subject = Object.new
|
160
|
+
expect(::Mbrao::Parser).to receive(:create_engine).with(:blank_rendered, :rendering).and_return(subject)
|
161
161
|
|
162
|
-
expect(
|
162
|
+
expect(subject).to receive(:render).with("CONTENT", {"engine" => :blank_rendered}, {content: "OK"})
|
163
163
|
::Mbrao::Parser.new.render("CONTENT", {engine: :blank_rendered}, {content: "OK"})
|
164
164
|
end
|
165
165
|
end
|
@@ -7,11 +7,11 @@
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
9
|
describe Mbrao::ParsingEngines::Base do
|
10
|
-
|
10
|
+
subject{ Mbrao::ParsingEngines::Base.new }
|
11
11
|
|
12
12
|
shared_examples_for("unimplemented") do |method|
|
13
13
|
it "should raise an exception" do
|
14
|
-
expect {
|
14
|
+
expect { subject.send(method, "CONTENT", {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -28,25 +28,25 @@ describe Mbrao::ParsingEngines::Base do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#parse" do
|
31
|
-
|
31
|
+
subject{ ::Mbrao::ParsingEngines::Base.new }
|
32
32
|
|
33
33
|
it "should forward to ::Mbrao::Content.create" do
|
34
|
-
expect(
|
35
|
-
allow(
|
34
|
+
expect(subject).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([{a: "b"}, "BODY"])
|
35
|
+
allow(subject).to receive(:parse_metadata).and_return({a: "b"})
|
36
36
|
expect(::Mbrao::Content).to receive(:create).with({a: "b"}, "BODY")
|
37
|
-
|
37
|
+
subject.parse("CONTENT", {a: "b"})
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return a Content object" do
|
41
|
-
allow(
|
42
|
-
allow(
|
43
|
-
expect(
|
41
|
+
allow(subject).to receive(:separate_components).with("CONTENT", {a: "b"}).and_return([])
|
42
|
+
allow(subject).to receive(:parse_metadata).and_return({})
|
43
|
+
expect(subject.parse("CONTENT", {a: "b"})).to be_a(::Mbrao::Content)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should separate_components" do
|
47
|
-
expect(
|
48
|
-
allow(
|
49
|
-
|
47
|
+
expect(subject).to receive(:separate_components).with("CONTENT", {a: "b"})
|
48
|
+
allow(subject).to receive(:parse_metadata).and_return({})
|
49
|
+
subject.parse("CONTENT", {a: "b"})
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
9
|
describe Mbrao::ParsingEngines::PlainText do
|
10
|
-
|
10
|
+
subject{ Mbrao::ParsingEngines::PlainText.new }
|
11
11
|
|
12
12
|
let(:sample_metadata) {
|
13
13
|
<<EOM
|
@@ -76,30 +76,30 @@ EOS4
|
|
76
76
|
|
77
77
|
describe "#separate_components" do
|
78
78
|
it "should return correct metadata and contents" do
|
79
|
-
expect(
|
79
|
+
expect(subject.separate_components(sample_valid)).to eq([sample_metadata.strip, sample_content.strip])
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should return the whole content if metadata are either incorrectly tagged or not present" do
|
83
|
-
expect(
|
84
|
-
expect(
|
83
|
+
expect(subject.separate_components(sample_invalid)).to eq(["", sample_invalid.strip])
|
84
|
+
expect(subject.separate_components(sample_no_metadata)).to eq(["", sample_no_metadata.strip])
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should use different tags" do
|
88
|
-
expect(
|
88
|
+
expect(subject.separate_components("[meta]{{metadata}}OK\n[/meta] REST", {meta_tags: ["[meta]", "[/meta]"]})).to eq(["{{metadata}}OK", "REST"])
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "#parse_metadata" do
|
93
93
|
it "should correctly parse YAML formatted metadata" do
|
94
|
-
expect(
|
94
|
+
expect(subject.parse_metadata("---\nyaml:\n :a: 'b'")).to eq({"yaml" => {a: "b"}})
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should return a default value if parsing failed" do
|
98
|
-
expect(
|
98
|
+
expect(subject.parse_metadata("---\n\"yaml:", {default: "DEFAULT"})).to eq("DEFAULT")
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should raise an exception if parsing failed and no default is available" do
|
102
|
-
expect {
|
102
|
+
expect { subject.parse_metadata("---\n\"yaml:") }.to raise_error(::Mbrao::Exceptions::InvalidMetadata)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -109,33 +109,33 @@ EOS4
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should return the original content if locales contains *" do
|
112
|
-
expect(parse_content(
|
112
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "*"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should use default locale if nothing is specified" do
|
116
116
|
::Mbrao::Parser.locale = :it
|
117
|
-
expect(parse_content(
|
117
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content)))).to eq(["START", "IT, EN", "MIDDLE", "END"])
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should ignore unclosed tag, trying to close the leftmost start tag" do
|
121
|
-
expect(parse_content(
|
121
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, "{{content: it}}\n{{content: en}}NO{{/content}}")))).to eq(["{{content: en}}NO"])
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should correctly filter by tag" do
|
125
|
-
expect(parse_content(
|
126
|
-
expect(parse_content(
|
127
|
-
expect(parse_content(
|
128
|
-
expect(parse_content(
|
129
|
-
expect(parse_content(
|
130
|
-
expect(parse_content(
|
131
|
-
expect(parse_content(
|
132
|
-
expect(parse_content(
|
125
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "en"))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
|
126
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "it"))).to eq(["START", "IT, EN", "MIDDLE", "END"])
|
127
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "es"))).to eq(["START", "MIDDLE", "!IT", "END"])
|
128
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), "fr"))).to eq(["START", "MIDDLE", "!IT and !ES", "!IT", "END"])
|
129
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["it", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "END"])
|
130
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
|
131
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "!IT and !ES", "EN in !IT", "!IT", "END"])
|
132
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample_nested_content), ["fr", "es", "en"]))).to eq(["START", "IT, EN", "MIDDLE", "EN in !IT", "!IT", "END"])
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should use different tags" do
|
136
136
|
sample = "[content-it]{{content: !it}}IT[/content]\nOK"
|
137
|
-
expect(parse_content(
|
138
|
-
expect(parse_content(
|
137
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample), "it", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["{{content: !it}}IT", "OK"])
|
138
|
+
expect(parse_content(subject.filter_content(::Mbrao::Content.create(nil, sample), "en", {content_tags: ["[content-%ARGS%]", "[/content]"]}))).to eq(["OK"])
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -7,11 +7,11 @@
|
|
7
7
|
require "spec_helper"
|
8
8
|
|
9
9
|
describe Mbrao::RenderingEngines::Base do
|
10
|
-
|
10
|
+
subject{ Mbrao::RenderingEngines::Base.new }
|
11
11
|
|
12
12
|
describe "#render" do
|
13
13
|
it "should raise an exception" do
|
14
|
-
expect {
|
14
|
+
expect { subject.render("CONTENT", {}, {}) }.to raise_error(Mbrao::Exceptions::Unimplemented)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|