Sha256: 8c2830d5497cd9b93b8ae40d81312a3a6633913a095233b90d70741f7ed96248

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module Optimacms
  class TemplateTranslation < ApplicationRecord
    self.table_name = 'cms_templates_translation'

    belongs_to :template, :foreign_key => 'item_id', :class_name => 'Template', :inverse_of => :translations

    delegate :basename, :basedirpath, :tpl_format, :is_type_partial?, to: :template

    ### content

    def content
      filename =  fullpath
      return nil if filename.nil?
      return '' if !File.exists? filename
      File.read(filename)
    end

    def content=(v)
      File.open(self.fullpath, "w+") do |f|
        f.write(v)
      end
    end


    ### path

    # base filename depending on  type
    # for page = name
    # for partial = _name
    def filename_base
      return '_'+basename if is_type_partial?
      basename
    end


    def path
      return nil if basename.nil?
      basedirpath + filename_base + Template.filename_lang_postfix(lang) + Template.filename_ext_with_dot(self.tpl_format)
    end

    def fullpath
      f = path
      return nil if f.nil?
      Template.base_dir + f
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
optimacms-0.4.3 app/models/optimacms/template_translation.rb
optimacms-0.4.2 app/models/optimacms/template_translation.rb