Sha256: 8c185c5a717eefd4d947d0badb6185707345b3c55bed32e6654f3c8e2ab2dd08

Contents?: true

Size: 1.04 KB

Versions: 58

Compression:

Stored size: 1.04 KB

Contents

module Optimacms

  class Layout < ActiveRecord::Base
    self.table_name = 'cms_templates'

    has_many :pages

    # scopes
    scope :main, -> { where(tpl_type: 'main')}

    # content

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

    def content=(v, lang='')
      File.open(content_filename_full(lang), "w+") do |f|
        f.write(v)
      end
    end

    def content_filename_full(lang)
      Layout.content_filename_dir + content_filename(lang)
    end

    def content_filename(lang='')
      self.name+content_filename_lang_postfix(lang)+'.'+content_filename_ext
    end


    def self.content_filename_dir
      #Rails.root.to_s + '/content/layouts/'
      Rails.root.to_s + '/app/views/layouts/'
    end

    def content_filename_lang_postfix(lang)
      return '' if lang==''
      return '.'+lang
    end

    def content_filename_ext
      return 'html.erb'
    end


  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
optimacms-0.3.35 app/models/optimacms/layout.rb
optimacms-0.3.34 app/models/optimacms/layout.rb
optimacms-0.3.30 app/models/optimacms/layout.rb
optimacms-0.3.29 app/models/optimacms/layout.rb
optimacms-0.3.23 app/models/optimacms/layout.rb
optimacms-0.3.15 app/models/optimacms/layout.rb
optimacms-0.3.12 app/models/optimacms/layout.rb
optimacms-0.3.11 app/models/optimacms/layout.rb
optimacms-0.2.26 app/models/optimacms/layout.rb
optimacms-0.2.25 app/models/optimacms/layout.rb
optimacms-0.2.24 app/models/optimacms/layout.rb
optimacms-0.3.4 app/models/optimacms/layout.rb
optimacms-0.3.3 app/models/optimacms/layout.rb
optimacms-0.2.21 app/models/optimacms/layout.rb
optimacms-0.2.20 app/models/optimacms/layout.rb
optimacms-0.2.16 app/models/optimacms/layout.rb
optimacms-0.2.15 app/models/optimacms/layout.rb
optimacms-0.2.14 app/models/optimacms/layout.rb
optimacms-0.2.13 app/models/optimacms/layout.rb
optimacms-0.2.12 app/models/optimacms/layout.rb