Sha256: cddd51ae88518d427475a41ea95e6dbe1b51ee36bfe022fdc7acc71ea1d547e2

Contents?: true

Size: 1.97 KB

Versions: 13

Compression:

Stored size: 1.97 KB

Contents

module Optimacms
  module ApplicationHelper

    #include ActionView::Helpers::ApplicationHelper
    #include SimpleFilter::FormsHelper


    def method_missing(method, *args, &block)
      main_app.send(method, *args, &block)
    rescue NoMethodError
      super
    end

    def tinymce_editor_insert_block
      '<pre>{{block:name:sub}}</pre>'
    end

    def eval_meta_string(s)
      eval('"'+s+'"')
    end

    def fix_quotes(s)
      s.gsub /"/, '\"'
    end

    def meta_tags(title=nil, keywords=nil, desc=nil)
      s = 'news "11"'
      s1 = s.gsub /"/, '\"'
      s2 = eval('"'+s1+'"')
      title ||= eval_meta_string(fix_quotes(@optimacms_meta_title))
      keywords ||= eval_meta_string(@optimacms_meta_keywords)
      desc ||= eval_meta_string(@optimacms_meta_description)


    return %(<title>#{title}</title>
<meta name="keywords" content="#{keywords}"/>
<meta name="description" content="#{desc}"/>
      ).html_safe
      #content_tag(:title, title)+
      #content_tag(:meta, nil, content: keywords, name: 'keywords')+
      #content_tag(:meta, nil, content: desc, name: 'description')
    end

    def block(name)
      x = Dir.pwd
      #y = File.expand_path File.dirname(__FILE__)
      d = File.dirname(@optimacms_tpl)

      # extensions
      extensions = ['', '.html.haml', '.html.erb', '.html']


      # try. HTML file in the current folder
      f = File.join(Dir.pwd, 'app', 'views', d, name+'.html')
      return render file: f if File.exists? f

      #
      names = []

      #
      parts = name.split /\//

      parts[-1] = '_'+parts[-1]
      name2 = parts.join('/')

      #
      names << [d, name]
      names << ["", name]

      names << [d, name2]
      names << ["", name2]


      # try 2
      names.each do |p|
        extensions.each do |ext|
          f = File.join(Dir.pwd, 'app', 'views', p[0], p[1]+ext)
          (return render file: f)      if File.exists? f
        end
      end

      # default render
      return render name
    end
    

    
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
optimacms-0.2.2 app/helpers/optimacms/application_helper.rb
optimacms-0.2.1 app/helpers/optimacms/application_helper.rb
optimacms-0.1.54 app/helpers/optimacms/application_helper.rb
optimacms-0.1.53 app/helpers/optimacms/application_helper.rb
optimacms-0.1.52 app/helpers/optimacms/application_helper.rb
optimacms-0.1.51 app/helpers/optimacms/application_helper.rb
optimacms-0.1.50 app/helpers/optimacms/application_helper.rb
optimacms-0.1.49 app/helpers/optimacms/application_helper.rb
optimacms-0.1.48 app/helpers/optimacms/application_helper.rb
optimacms-0.1.47 app/helpers/optimacms/application_helper.rb
optimacms-0.1.45 app/helpers/optimacms/application_helper.rb
optimacms-0.1.44 app/helpers/optimacms/application_helper.rb
optimacms-0.1.43 app/helpers/optimacms/application_helper.rb