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 #1 from the-curve-consulting/james/header-footer
Adding support for page numbers
- Loading branch information
Showing
20 changed files
with
631 additions
and
37 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
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,33 @@ | ||
require 'caracal/core/models/footer_model' | ||
require 'caracal/errors' | ||
|
||
|
||
module Caracal | ||
module Core | ||
|
||
# This module encapsulates all the functionality related to adding a | ||
# footer on every page of the document. | ||
# | ||
module Footer | ||
def self.included(base) | ||
base.class_eval do | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
def footer(*args, &block) | ||
options = Caracal::Utilities.extract_options!(args) | ||
|
||
model = Caracal::Core::Models::FooterModel.new(options, &block) | ||
|
||
@footer_content = model | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'caracal/core/models/header_model' | ||
require 'caracal/errors' | ||
|
||
|
||
module Caracal | ||
module Core | ||
|
||
# This module encapsulates all the functionality related to adding a header | ||
# to every page of the document. | ||
# | ||
module Header | ||
def self.included(base) | ||
base.class_eval do | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
def header(*args, &block) | ||
options = Caracal::Utilities.extract_options!(args) | ||
|
||
model = Caracal::Core::Models::HeaderModel.new(options, &block) | ||
|
||
@header_content = model | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
require 'caracal/core/models/base_model' | ||
|
||
|
||
module Caracal | ||
module Core | ||
module Models | ||
|
||
# This class encapsulates the logic needed to store and manipulate | ||
# text data. | ||
# | ||
class FieldModel < BaseModel | ||
|
||
#-------------------------------------------------- | ||
# Configuration | ||
#-------------------------------------------------- | ||
|
||
# constants | ||
const_set(:TYPE_MAP, { page: 'PAGE', numpages: 'NUMPAGES' }) | ||
|
||
# accessors | ||
attr_reader :field_dirty | ||
attr_reader :field_type | ||
attr_reader :field_style | ||
attr_reader :field_font | ||
attr_reader :field_color | ||
attr_reader :field_size | ||
attr_reader :field_bold | ||
attr_reader :field_italic | ||
attr_reader :field_underline | ||
attr_reader :field_bgcolor | ||
attr_reader :field_highlight_color | ||
attr_reader :field_vertical_align | ||
|
||
#------------------------------------------------------------- | ||
# Public Class Methods | ||
#------------------------------------------------------------- | ||
|
||
def self.formatted_type(type) | ||
TYPE_MAP.fetch(type.to_s.to_sym) | ||
end | ||
|
||
|
||
#------------------------------------------------------------- | ||
# Public Instance Methods | ||
#------------------------------------------------------------- | ||
|
||
#=============== GETTERS ============================== | ||
|
||
def formatted_type | ||
self.class.formatted_type(field_type) | ||
end | ||
|
||
#========== GETTERS =============================== | ||
|
||
# .run_attributes | ||
def run_attributes | ||
{ | ||
style: field_style, | ||
font: field_font, | ||
color: field_color, | ||
size: field_size, | ||
bold: field_bold, | ||
italic: field_italic, | ||
underline: field_underline, | ||
bgcolor: field_bgcolor, | ||
highlight_color: field_highlight_color, | ||
vertical_align: field_vertical_align | ||
} | ||
end | ||
|
||
|
||
#========== SETTERS =============================== | ||
|
||
# booleans | ||
[:bold, :italic, :underline].each do |m| | ||
define_method "#{ m }" do |value| | ||
instance_variable_set("@field_#{ m }", !!value) | ||
end | ||
end | ||
|
||
# integers | ||
[:size].each do |m| | ||
define_method "#{ m }" do |value| | ||
instance_variable_set("@field_#{ m }", value.to_i) | ||
end | ||
end | ||
|
||
# strings | ||
[:bgcolor, :color, :dirty, :font, :highlight_color, :style, :type,].each do |m| | ||
define_method "#{ m }" do |value| | ||
instance_variable_set("@field_#{ m }", value.to_s) | ||
end | ||
end | ||
|
||
# symbols | ||
[:vertical_align].each do |m| | ||
define_method "#{ m }" do |value| | ||
instance_variable_set("@field_#{ m }", value.to_s.to_sym) | ||
end | ||
end | ||
|
||
|
||
#========== VALIDATION ============================ | ||
|
||
def valid? | ||
a = [:type] | ||
a.map { |m| send("field_#{ m }") }.compact.size == a.size | ||
end | ||
|
||
|
||
#-------------------------------------------------- | ||
# Private Methods | ||
#-------------------------------------------------- | ||
private | ||
|
||
def option_keys | ||
[:type, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :highlight_color, :vertical_align] | ||
end | ||
|
||
def method_missing(method, *args, &block) | ||
# TODO: Better field centric description | ||
|
||
# I'm on the fence with respect to this implementation. We're ignoring | ||
# :method_missing errors to allow syntax flexibility for paragraph-type | ||
# models. The issue is the syntax format of those models--the way we pass | ||
# the content value as a special argument--coupled with the model's | ||
# ability to accept nested instructions. | ||
# | ||
# By ignoring method missing errors here, we can pass the entire paragraph | ||
# block in the initial, built-in call to :text. | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'caracal/core/models/base_model' | ||
require 'caracal/core/models/margin_model' | ||
require 'caracal/core/models/paragraph_model' | ||
|
||
|
||
module Caracal | ||
module Core | ||
module Models | ||
|
||
# This class handles block options passed to tables via their data | ||
# collections. | ||
# | ||
class FooterModel < BaseModel | ||
|
||
#------------------------------------------------------------- | ||
# Configuration | ||
#------------------------------------------------------------- | ||
|
||
# initialization | ||
def initialize(options={}, &block) | ||
super options, &block | ||
end | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
#=============== DATA ACCESSORS ======================= | ||
|
||
def contents | ||
@contents ||= [] | ||
end | ||
|
||
#=============== VALIDATION =========================== | ||
|
||
def valid? | ||
contents.size > 0 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'caracal/core/models/base_model' | ||
require 'caracal/core/models/margin_model' | ||
require 'caracal/core/models/paragraph_model' | ||
|
||
|
||
module Caracal | ||
module Core | ||
module Models | ||
|
||
# This class handles block options passed to tables via their data | ||
# collections. | ||
# | ||
class HeaderModel < BaseModel | ||
|
||
#------------------------------------------------------------- | ||
# Configuration | ||
#------------------------------------------------------------- | ||
|
||
# initialization | ||
def initialize(options={}, &block) | ||
super options, &block | ||
end | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
#=============== DATA ACCESSORS ======================= | ||
|
||
def contents | ||
@contents ||= [] | ||
end | ||
|
||
#=============== VALIDATION =========================== | ||
|
||
def valid? | ||
contents.size > 0 | ||
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
Oops, something went wrong.