forked from urvin-compliance/caracal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from the-curve-consulting/mbarber/PWM-263
Specify table of contents in document
- Loading branch information
Showing
9 changed files
with
88 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'caracal/core/models/field_model' | ||
require 'caracal/errors' | ||
|
||
|
||
module Caracal | ||
module Core | ||
|
||
# This module encapsulates all the functionality related to fields | ||
# | ||
module Fields | ||
def self.included(base) | ||
base.class_eval do | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
def field(*args, &block) | ||
options = Caracal::Utilities.extract_options!(args) | ||
options.merge!({ type: args.first }) if args.first | ||
|
||
model = Caracal::Core::Models::FieldModel.new(options, &block) | ||
|
||
if model.valid? | ||
contents << model | ||
end | ||
|
||
model | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe Caracal::Core::Fields do | ||
subject { Caracal::Document.new } | ||
|
||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
describe 'public method tests' do | ||
|
||
# .table | ||
describe '.field' do | ||
let!(:size) { subject.contents.size } | ||
|
||
before { subject.field :table_of_contents } | ||
|
||
it { expect(subject.contents.size).to eq size + 1 } | ||
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::FieldModel) } | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters