caracal_the_curve 1.4.1
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 +7 -0
- data/.github/workflows/main.yml +22 -0
- data/.github/workflows/publish_gem.yml +40 -0
- data/.gitignore +25 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +141 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +842 -0
- data/Rakefile +7 -0
- data/caracal.gemspec +28 -0
- data/lib/caracal/core/bookmarks.rb +52 -0
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/file_name.rb +43 -0
- data/lib/caracal/core/fonts.rb +75 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/images.rb +37 -0
- data/lib/caracal/core/list_styles.rb +93 -0
- data/lib/caracal/core/lists.rb +57 -0
- data/lib/caracal/core/models/base_model.rb +51 -0
- data/lib/caracal/core/models/bookmark_model.rb +86 -0
- data/lib/caracal/core/models/border_model.rb +120 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/font_model.rb +64 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/image_model.rb +133 -0
- data/lib/caracal/core/models/line_break_model.rb +15 -0
- data/lib/caracal/core/models/link_model.rb +94 -0
- data/lib/caracal/core/models/list_item_model.rb +108 -0
- data/lib/caracal/core/models/list_model.rb +132 -0
- data/lib/caracal/core/models/list_style_model.rb +118 -0
- data/lib/caracal/core/models/margin_model.rb +76 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +61 -0
- data/lib/caracal/core/models/page_number_model.rb +95 -0
- data/lib/caracal/core/models/page_size_model.rb +79 -0
- data/lib/caracal/core/models/paragraph_model.rb +186 -0
- data/lib/caracal/core/models/relationship_model.rb +114 -0
- data/lib/caracal/core/models/rule_model.rb +27 -0
- data/lib/caracal/core/models/style_model.rb +165 -0
- data/lib/caracal/core/models/table_cell_model.rb +176 -0
- data/lib/caracal/core/models/table_model.rb +206 -0
- data/lib/caracal/core/models/text_model.rb +118 -0
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_breaks.rb +29 -0
- data/lib/caracal/core/page_numbers.rb +58 -0
- data/lib/caracal/core/page_settings.rb +74 -0
- data/lib/caracal/core/relationships.rb +90 -0
- data/lib/caracal/core/rules.rb +35 -0
- data/lib/caracal/core/styles.rb +86 -0
- data/lib/caracal/core/tables.rb +42 -0
- data/lib/caracal/core/text.rb +75 -0
- data/lib/caracal/document.rb +272 -0
- data/lib/caracal/errors.rb +23 -0
- data/lib/caracal/renderers/app_renderer.rb +41 -0
- data/lib/caracal/renderers/content_types_renderer.rb +54 -0
- data/lib/caracal/renderers/core_renderer.rb +44 -0
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +427 -0
- data/lib/caracal/renderers/fonts_renderer.rb +56 -0
- data/lib/caracal/renderers/footer_renderer.rb +90 -0
- data/lib/caracal/renderers/numbering_renderer.rb +88 -0
- data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
- data/lib/caracal/renderers/relationships_renderer.rb +48 -0
- data/lib/caracal/renderers/settings_renderer.rb +58 -0
- data/lib/caracal/renderers/styles_renderer.rb +181 -0
- data/lib/caracal/renderers/xml_renderer.rb +83 -0
- data/lib/caracal/utilities.rb +23 -0
- data/lib/caracal/version.rb +3 -0
- data/lib/caracal.rb +40 -0
- data/lib/tilt/caracal.rb +21 -0
- data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
- data/spec/lib/caracal/core/file_name_spec.rb +54 -0
- data/spec/lib/caracal/core/fonts_spec.rb +119 -0
- data/spec/lib/caracal/core/iframes_spec.rb +29 -0
- data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
- data/spec/lib/caracal/core/images_spec.rb +25 -0
- data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
- data/spec/lib/caracal/core/lists_spec.rb +43 -0
- data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
- data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
- data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
- data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
- data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
- data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
- data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
- data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
- data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
- data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
- data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
- data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
- data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
- data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
- data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
- data/spec/lib/caracal/core/relationships_spec.rb +119 -0
- data/spec/lib/caracal/core/rules_spec.rb +25 -0
- data/spec/lib/caracal/core/styles_spec.rb +129 -0
- data/spec/lib/caracal/core/tables_spec.rb +25 -0
- data/spec/lib/caracal/core/text_spec.rb +52 -0
- data/spec/lib/caracal/errors_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +292 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
# We're using this strategy borrowed from ActiveSupport to
|
2
|
+
# make command syntax a little more flexible. In a perfect
|
3
|
+
# world we'd just use the double splat feature of Ruby, but
|
4
|
+
# support for that is pretty limited at this point, so we're
|
5
|
+
# going the extra mile to be cool.
|
6
|
+
#
|
7
|
+
module Caracal
|
8
|
+
class Utilities
|
9
|
+
|
10
|
+
#-------------------------------------------------------------
|
11
|
+
# Public Class Methods
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
|
14
|
+
def self.extract_options!(args)
|
15
|
+
if args.last.is_a?(Hash)
|
16
|
+
args.pop
|
17
|
+
else
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/caracal.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#------------------------------------------------
|
2
|
+
# Requirements
|
3
|
+
#------------------------------------------------
|
4
|
+
|
5
|
+
# external dependencies
|
6
|
+
require 'tilt'
|
7
|
+
|
8
|
+
# odds & ends
|
9
|
+
require 'caracal/errors'
|
10
|
+
require 'caracal/utilities'
|
11
|
+
require 'caracal/version'
|
12
|
+
|
13
|
+
# document
|
14
|
+
require 'caracal/document'
|
15
|
+
|
16
|
+
|
17
|
+
#------------------------------------------------
|
18
|
+
# Extra Setup
|
19
|
+
#------------------------------------------------
|
20
|
+
|
21
|
+
# Convenience method for finding root directory.
|
22
|
+
#
|
23
|
+
module Caracal
|
24
|
+
def self.root
|
25
|
+
File.dirname __dir__
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# Add functions to table cell model. we do this here to
|
31
|
+
# avoid a circular require between Caracal::Core::Tables
|
32
|
+
# and Caracal::Core::Models::TableCellModel.
|
33
|
+
#
|
34
|
+
Caracal::Core::Models::TableCellModel.class_eval do
|
35
|
+
include Caracal::Core::Images
|
36
|
+
include Caracal::Core::Lists
|
37
|
+
include Caracal::Core::Rules
|
38
|
+
include Caracal::Core::Tables
|
39
|
+
include Caracal::Core::Text
|
40
|
+
end
|
data/lib/tilt/caracal.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'tilt/template'
|
2
|
+
require 'caracal'
|
3
|
+
|
4
|
+
|
5
|
+
module Tilt
|
6
|
+
class CaracalTemplate < Template
|
7
|
+
self.default_mime_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
@code =<<-RUBY
|
11
|
+
Caracal::Document.render do |docx|
|
12
|
+
#{ data }
|
13
|
+
end
|
14
|
+
RUBY
|
15
|
+
end
|
16
|
+
|
17
|
+
def precompiled_template(locals)
|
18
|
+
@code
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Bookmarks do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
# .bookmark_start
|
14
|
+
describe '.bookmark_start' do
|
15
|
+
let!(:size) { subject.contents.size }
|
16
|
+
|
17
|
+
before { subject.send('bookmark_start', id: '123', name: 'abc') }
|
18
|
+
|
19
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
20
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::BookmarkModel) }
|
21
|
+
end
|
22
|
+
|
23
|
+
# .bookmark_end
|
24
|
+
describe '.bookmark_end' do
|
25
|
+
let!(:size) { subject.contents.size }
|
26
|
+
|
27
|
+
before { subject.send('bookmark_end', id: '123') }
|
28
|
+
|
29
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
30
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::BookmarkModel) }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::FileName do
|
4
|
+
let(:file_name) { 'test.docx' }
|
5
|
+
|
6
|
+
subject { Caracal::Document.new }
|
7
|
+
|
8
|
+
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
# Configuration
|
11
|
+
#-------------------------------------------------------------
|
12
|
+
|
13
|
+
describe 'configuration tests' do
|
14
|
+
|
15
|
+
# constants
|
16
|
+
describe 'file name constants' do
|
17
|
+
it { expect(subject.class::DEFAULT_FILE_NAME).to eq 'caracal.docx' }
|
18
|
+
end
|
19
|
+
|
20
|
+
# accessors
|
21
|
+
describe 'file name readers' do
|
22
|
+
it { expect(subject.name).to eq 'caracal.docx' }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
#-------------------------------------------------------------
|
29
|
+
# Public Methods
|
30
|
+
#-------------------------------------------------------------
|
31
|
+
|
32
|
+
describe 'public method tests' do
|
33
|
+
|
34
|
+
# .file_name
|
35
|
+
describe '.file_name' do
|
36
|
+
let(:new_name) { 'example.docx' }
|
37
|
+
let(:actual) { subject.name }
|
38
|
+
|
39
|
+
before { subject.file_name(new_name) }
|
40
|
+
|
41
|
+
describe 'when argument provided' do
|
42
|
+
it { expect(actual).to eq new_name }
|
43
|
+
end
|
44
|
+
describe 'when argument nil' do
|
45
|
+
let!(:previous) { subject.name }
|
46
|
+
let(:new_name) { nil }
|
47
|
+
|
48
|
+
it { expect(actual).to eq previous }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Fonts do
|
4
|
+
let(:f1) { Caracal::Core::Models::FontModel.new({ name: 'Helvetica' }) }
|
5
|
+
let(:f2) { Caracal::Core::Models::FontModel.new({ name: 'Garamond' }) }
|
6
|
+
|
7
|
+
subject { Caracal::Document.new }
|
8
|
+
|
9
|
+
|
10
|
+
#-------------------------------------------------------------
|
11
|
+
# Class Methods
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
|
14
|
+
describe 'public class tests' do
|
15
|
+
|
16
|
+
# .default_fonts
|
17
|
+
describe '.default_fonts' do
|
18
|
+
let(:expected) { ['Arial', 'Trebuchet MS'] }
|
19
|
+
let(:actual) { subject.class.default_fonts.map { |r| r[:name] } }
|
20
|
+
|
21
|
+
it { expect(actual).to eq expected }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#-------------------------------------------------------------
|
28
|
+
# Public Methods
|
29
|
+
#-------------------------------------------------------------
|
30
|
+
|
31
|
+
describe 'public method tests' do
|
32
|
+
|
33
|
+
#============== ATTRIBUTES =====================
|
34
|
+
|
35
|
+
# .font
|
36
|
+
describe '.font' do
|
37
|
+
it 'delegates font to registration method' do
|
38
|
+
expect(subject).to receive(:register_font)
|
39
|
+
subject.font({ name: 'Helvetica' })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#============== GETTERS ========================
|
45
|
+
|
46
|
+
# .fonts
|
47
|
+
describe '.fonts' do
|
48
|
+
it { expect(subject.fonts).to be_a(Array) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# .find_font
|
52
|
+
describe '.find_font' do
|
53
|
+
let(:actual) { subject.find_font(key) }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:fonts).and_return([f1])
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'when key is registered' do
|
60
|
+
let(:key) { f1.font_name }
|
61
|
+
|
62
|
+
it { expect(actual).to eq f1 }
|
63
|
+
end
|
64
|
+
describe 'when key is not registered' do
|
65
|
+
let(:key) { f2.font_name }
|
66
|
+
|
67
|
+
it { expect(actual).to eq nil }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
#============== REGISTRATION ========================
|
73
|
+
|
74
|
+
# .register_font
|
75
|
+
describe '.register_font' do
|
76
|
+
let(:default_length) { subject.class.default_fonts.size }
|
77
|
+
|
78
|
+
describe 'when not already registered' do
|
79
|
+
before do
|
80
|
+
subject.register_font(f1)
|
81
|
+
end
|
82
|
+
|
83
|
+
it { expect(subject.fonts.size).to eq default_length + 1 }
|
84
|
+
end
|
85
|
+
describe 'when already registered' do
|
86
|
+
before do
|
87
|
+
subject.register_font(f1)
|
88
|
+
subject.register_font(f1)
|
89
|
+
end
|
90
|
+
|
91
|
+
it { expect(subject.fonts.size).to eq default_length + 1 }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# .unregister_font
|
96
|
+
describe '.unregister_font' do
|
97
|
+
let(:default_length) { subject.class.default_fonts.size }
|
98
|
+
|
99
|
+
describe 'when registered' do
|
100
|
+
before do
|
101
|
+
subject.register_font(f1)
|
102
|
+
subject.unregister_font(f1.font_name)
|
103
|
+
end
|
104
|
+
|
105
|
+
it { expect(subject.fonts.size).to eq default_length }
|
106
|
+
end
|
107
|
+
describe 'when not registered' do
|
108
|
+
before do
|
109
|
+
subject.register_font(f1)
|
110
|
+
subject.unregister_font(f2.font_name)
|
111
|
+
end
|
112
|
+
|
113
|
+
it { expect(subject.fonts.size).to eq default_length + 1 }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::IFrames do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
# .img
|
14
|
+
describe '.iframes' do
|
15
|
+
let!(:size) { subject.contents.size }
|
16
|
+
|
17
|
+
before do
|
18
|
+
path = File.join(Caracal.root, 'spec', 'support', '_fixtures', 'snippet.docx')
|
19
|
+
data = File.open(path).read
|
20
|
+
subject.iframe data: data
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
24
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::IFrameModel) }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Ignorables do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
#============== ATTRIBUTES =====================
|
14
|
+
|
15
|
+
# .ignorable
|
16
|
+
describe '.ignorable' do
|
17
|
+
it 'delegates to registration method' do
|
18
|
+
expect(subject).to receive(:register_ignorable)
|
19
|
+
subject.ignorable('dummy')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
#============== GETTERS ========================
|
25
|
+
|
26
|
+
# .ignorables
|
27
|
+
describe '.ignorables' do
|
28
|
+
it { expect(subject.ignorables).to be_a(Array) }
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
#============== REGISTRATION ========================
|
33
|
+
|
34
|
+
# .register_ignorable
|
35
|
+
describe '.register_ignorable' do
|
36
|
+
let(:default_length) { 0 }
|
37
|
+
|
38
|
+
describe 'when not already registered' do
|
39
|
+
before do
|
40
|
+
subject.register_ignorable('dummy')
|
41
|
+
end
|
42
|
+
|
43
|
+
it { expect(subject.ignorables.size).to eq default_length + 1 }
|
44
|
+
end
|
45
|
+
describe 'when already registered' do
|
46
|
+
before do
|
47
|
+
subject.register_ignorable('dummy')
|
48
|
+
subject.register_ignorable('dummy')
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(subject.ignorables.size).to eq default_length + 1 }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# .unregister_ignorable
|
56
|
+
describe '.unregister_ignorable' do
|
57
|
+
let(:default_length) { 0 }
|
58
|
+
|
59
|
+
describe 'when registered' do
|
60
|
+
before do
|
61
|
+
subject.register_ignorable('dummy')
|
62
|
+
subject.unregister_ignorable('dummy')
|
63
|
+
end
|
64
|
+
|
65
|
+
it { expect(subject.ignorables.size).to eq default_length }
|
66
|
+
end
|
67
|
+
describe 'when not registered' do
|
68
|
+
before do
|
69
|
+
subject.register_ignorable('dummy')
|
70
|
+
subject.unregister_ignorable('bogus')
|
71
|
+
end
|
72
|
+
|
73
|
+
it { expect(subject.ignorables.size).to eq default_length + 1 }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Images do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
# .img
|
14
|
+
describe '.img' do
|
15
|
+
let!(:size) { subject.contents.size }
|
16
|
+
|
17
|
+
before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190 }
|
18
|
+
|
19
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
20
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::ListStyles do
|
4
|
+
let(:s1) { Caracal::Core::Models::ListStyleModel.new({ type: :ordered, level: 10, format: 'decimal', value: '%1.' }) }
|
5
|
+
let(:s2) { Caracal::Core::Models::ListStyleModel.new({ type: :ordered, level: 11, format: 'lowerLetter', value: '%2.' }) }
|
6
|
+
|
7
|
+
subject { Caracal::Document.new }
|
8
|
+
|
9
|
+
|
10
|
+
#-------------------------------------------------------------
|
11
|
+
# Class Methods
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
|
14
|
+
describe 'public class tests' do
|
15
|
+
|
16
|
+
# .default_list_styles
|
17
|
+
describe '.default_list_styles' do
|
18
|
+
let(:expected) { 18 }
|
19
|
+
let(:actual) { subject.class.default_list_styles.size }
|
20
|
+
|
21
|
+
it {expect(actual).to eq expected }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#-------------------------------------------------------------
|
28
|
+
# Public Methods
|
29
|
+
#-------------------------------------------------------------
|
30
|
+
|
31
|
+
describe 'public method tests' do
|
32
|
+
|
33
|
+
#============== ATTRIBUTES =====================
|
34
|
+
|
35
|
+
# .list_style
|
36
|
+
describe '.list_style' do
|
37
|
+
it 'delegates to registration method' do
|
38
|
+
expect(subject).to receive(:register_list_style)
|
39
|
+
subject.list_style({ type: :ordered, level: 2, format: 'decimal', value: '2f.' })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#============== GETTERS ========================
|
45
|
+
|
46
|
+
# .list_styles
|
47
|
+
describe '.list_styles' do
|
48
|
+
it { expect(subject.list_styles).to be_a(Array) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# .find_list_style
|
52
|
+
describe '.find_list_style' do
|
53
|
+
let(:actual) { subject.find_list_style(type, level) }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:list_styles).and_return([s1])
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'when key is registered' do
|
60
|
+
let(:type) { s1.style_type }
|
61
|
+
let(:level) { s1.style_level }
|
62
|
+
|
63
|
+
it { expect(actual).to eq s1 }
|
64
|
+
end
|
65
|
+
describe 'when key is not registered' do
|
66
|
+
let(:type) { s2.style_type }
|
67
|
+
let(:level) { s2.style_level }
|
68
|
+
|
69
|
+
it { expect(actual).to eq nil }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
#============== REGISTRATION ========================
|
75
|
+
|
76
|
+
# .register_list_style
|
77
|
+
describe '.register_list_style' do
|
78
|
+
let(:default_length) { subject.class.default_list_styles.size }
|
79
|
+
|
80
|
+
describe 'when not already registered' do
|
81
|
+
before do
|
82
|
+
subject.register_list_style(s1)
|
83
|
+
end
|
84
|
+
|
85
|
+
it { expect(subject.list_styles.size).to eq default_length + 1 }
|
86
|
+
end
|
87
|
+
describe 'when already registered' do
|
88
|
+
before do
|
89
|
+
subject.register_list_style(s1)
|
90
|
+
subject.register_list_style(s1)
|
91
|
+
end
|
92
|
+
|
93
|
+
it { expect(subject.list_styles.size).to eq default_length + 1 }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# .unregister_list_style
|
98
|
+
describe '.unregister_list_style' do
|
99
|
+
let(:default_length) { subject.class.default_list_styles.size }
|
100
|
+
|
101
|
+
describe 'when registered' do
|
102
|
+
before do
|
103
|
+
subject.register_list_style(s1)
|
104
|
+
subject.unregister_list_style(s1.style_type, s1.style_level)
|
105
|
+
end
|
106
|
+
|
107
|
+
it { expect(subject.list_styles.size).to eq default_length }
|
108
|
+
end
|
109
|
+
describe 'when not registered' do
|
110
|
+
before do
|
111
|
+
subject.register_list_style(s1)
|
112
|
+
subject.unregister_list_style(s2.style_type, s2.style_level)
|
113
|
+
end
|
114
|
+
|
115
|
+
it { expect(subject.list_styles.size).to eq default_length + 1 }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Lists do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
# .ol
|
14
|
+
describe '.ol' do
|
15
|
+
let!(:size) { subject.contents.size }
|
16
|
+
|
17
|
+
before do
|
18
|
+
subject.ol do
|
19
|
+
li 'Item 1'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
24
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# .ul
|
28
|
+
describe '.ul' do
|
29
|
+
let!(:size) { subject.contents.size }
|
30
|
+
|
31
|
+
before do
|
32
|
+
subject.ul do
|
33
|
+
li 'Item 1'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
38
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::BaseModel do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
#=============== VALIDATION ===========================
|
14
|
+
|
15
|
+
describe '.valid?' do
|
16
|
+
it { expect(subject.valid?).to eq true }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
#-------------------------------------------------------------
|
23
|
+
# Private Methods
|
24
|
+
#-------------------------------------------------------------
|
25
|
+
|
26
|
+
describe 'private method tests' do
|
27
|
+
|
28
|
+
# .option_keys
|
29
|
+
describe '.option_keys' do
|
30
|
+
let(:actual) { subject.send(:option_keys).sort }
|
31
|
+
let(:expected) { [] }
|
32
|
+
|
33
|
+
it { expect(actual).to eq expected }
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|