Module: Templatr::ActsAsTemplatable::InstanceMethods

Defined in:
lib/templatr/acts_as_templatable.rb

Instance Method Summary collapse

Instance Method Details

#additional_tagsObject



100
101
102
# File 'lib/templatr/acts_as_templatable.rb', line 100

def additional_tags
  tags.where("field_id IS NULL")
end

#can_change_template?Boolean

Returns true if the record is still able to choose which template to use

Returns:

  • (Boolean)


85
86
87
# File 'lib/templatr/acts_as_templatable.rb', line 85

def can_change_template?
  !persisted? || !template.present?
end

#template_tags(options = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/templatr/acts_as_templatable.rb', line 89

def template_tags(options = {})
  existing_tags = tags.joins(:field).reorder('templatr_fields.field_group_id, templatr_fields.order')

  return existing_tags unless options[:include_blank]

  # Add non-populated tags so that they show in the form
  template_fields.collect do |field|
    existing_tags.detect {|tag| tag.field == field } || Tag.new(:field => field)
  end
end