Sha256: b6e253e005887678a6f9dedf635ffd9acd3184faad0c4b0d1dfd0a96290097ba

Contents?: true

Size: 1.49 KB

Versions: 27

Compression:

Stored size: 1.49 KB

Contents

module Optimacms
  class Resource < ActiveRecord::Base
    self.table_name = 'cms_resources'

    # translation
    translates :content
    globalize_accessors :locales => Language.list_all

    ### search
    paginates_per 20

    ### search
    searchable_by_simple_filter


    ##
    def self.v(name)
      where(name: name).first.content rescue ''
    end

    ##
    def self.method_missing(method_sym, *arguments, &block)
      # the first argument is a Symbol, so you need to_s it if you want to pattern match
      #if method_sym.to_s =~ /^find_by_(.*)$/
        v(method_sym.to_s)
      #else
      #  super
      #end
    end

    ###
    def get_usages

      res = []
      dd = Rails.root.join('app', 'views')
      Dir.glob("#{dd}/**/*").each do |f|
        r = {}

        next if File.directory?(f)

        r[:path] = f
        r[:shortpath] = f.gsub(/#{dd}\/?/,'')

        # find in file
        hits = []
        File.foreach(f).with_index do |s, line_ind|
          #puts "#{line_num}: #{line}"

          if s[/msg\.#{name}/]
            hits << {line: s, line_ind: line_ind}
          end
        end

        r[:hits] = hits

        if hits.count > 0
          # find template
          tp = r[:shortpath].gsub(/\.html\.(haml|erb)$/, '')
          tp.gsub! /\/_/, '/'

          row_template = Optimacms::Template.where(:basepath=>tp).first
          if row_template
            r[:template_id] = row_template.id
          end

          res << r
        end

      end
      res
    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
optimacms-0.1.61 app/models/optimacms/resource.rb
optimacms-0.4.3 app/models/optimacms/resource.rb
optimacms-0.4.2 app/models/optimacms/resource.rb
optimacms-0.3.35 app/models/optimacms/resource.rb
optimacms-0.3.34 app/models/optimacms/resource.rb
optimacms-0.3.30 app/models/optimacms/resource.rb
optimacms-0.3.29 app/models/optimacms/resource.rb
optimacms-0.3.23 app/models/optimacms/resource.rb
optimacms-0.3.15 app/models/optimacms/resource.rb
optimacms-0.3.12 app/models/optimacms/resource.rb
optimacms-0.3.11 app/models/optimacms/resource.rb
optimacms-0.3.9 app/models/optimacms/resource.rb
optimacms-0.3.8 app/models/optimacms/resource.rb
optimacms-0.3.7 app/models/optimacms/resource.rb
optimacms-0.3.6 app/models/optimacms/resource.rb
optimacms-0.3.5 app/models/optimacms/resource.rb
optimacms-0.2.26 app/models/optimacms/resource.rb
optimacms-0.2.25 app/models/optimacms/resource.rb
optimacms-0.2.24 app/models/optimacms/resource.rb
optimacms-0.3.4 app/models/optimacms/resource.rb