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.2.11 app/models/optimacms/layout.rb
optimacms-0.2.9 app/models/optimacms/layout.rb
optimacms-0.2.3 app/models/optimacms/layout.rb
optimacms-0.1.59 app/models/optimacms/layout.rb
optimacms-0.1.58 app/models/optimacms/layout.rb
optimacms-0.1.57 app/models/optimacms/layout.rb
optimacms-0.1.56 app/models/optimacms/layout.rb
optimacms-0.1.54 app/models/optimacms/layout.rb
optimacms-0.1.51 app/models/optimacms/layout.rb
optimacms-0.1.50 app/models/optimacms/layout.rb
optimacms-0.1.49 app/models/optimacms/layout.rb
optimacms-0.1.48 app/models/optimacms/layout.rb
optimacms-0.1.47 app/models/optimacms/layout.rb
optimacms-0.1.45 app/models/optimacms/layout.rb
optimacms-0.1.44 app/models/optimacms/layout.rb
optimacms-0.1.43 app/models/optimacms/layout.rb
optimacms-0.1.41 app/models/optimacms/layout.rb
optimacms-0.1.40 app/models/optimacms/layout.rb
optimacms-0.1.39 app/models/optimacms/layout.rb
optimacms-0.1.38 app/models/optimacms/layout.rb