hancock_cms_pages 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/hancock/pages/blocksetable.rb +48 -14
- data/app/controllers/concerns/hancock/pages/localizeable.rb +5 -5
- data/app/controllers/concerns/hancock/pages/nav_menu.rb +10 -5
- data/app/controllers/concerns/hancock/pages/seo_pages.rb +3 -3
- data/app/helpers/hancock/pages/blocksets_helper.rb +26 -0
- data/app/helpers/hancock/pages/pages_helper.rb +11 -0
- data/app/models/concerns/hancock/pages/connectable.rb +1 -1
- data/app/views/blocks/_cached_blockset_navigation.html.slim +26 -0
- data/app/views/blocks/_cached_navigation.html.slim +26 -0
- data/app/views/blocks/_header.html.slim +9 -1
- data/app/views/hancock/pages/pages/show.html.slim +14 -1
- data/app/views/shared/_obj.html.slim +21 -25
- data/config/locales/hancock.pages.ru.yml +5 -0
- data/hancock_cms_pages.gemspec +3 -3
- data/lib/generators/hancock/pages/config/{install_generator.rb → config_generator.rb} +0 -0
- data/lib/generators/hancock/pages/config/templates/hancock_pages.erb +19 -6
- data/lib/generators/hancock/pages/controllers/decorators_generator.rb +24 -0
- data/lib/generators/hancock/pages/{migration_generator.rb → migrations/migrations_generator.rb} +3 -3
- data/lib/generators/hancock/pages/{templates → migrations/templates}/migration_blocks.rb +0 -0
- data/lib/generators/hancock/pages/{templates → migrations/templates}/migration_pages.rb +0 -0
- data/lib/generators/hancock/pages/models/templates/block.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/blockset.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/menu.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/page.erb +7 -7
- data/lib/hancock/pages/admin.rb +35 -8
- data/lib/hancock/pages/admin/block.rb +14 -1
- data/lib/hancock/pages/admin/blockset.rb +34 -11
- data/lib/hancock/pages/admin/menu.rb +3 -1
- data/lib/hancock/pages/admin/page.rb +35 -5
- data/lib/hancock/pages/configuration.rb +28 -5
- data/lib/hancock/pages/controllers/pages.rb +10 -1
- data/lib/hancock/pages/engine.rb +59 -0
- data/lib/hancock/pages/models/active_record/blockset.rb +2 -1
- data/lib/hancock/pages/models/block.rb +234 -55
- data/lib/hancock/pages/models/blockset.rb +50 -38
- data/lib/hancock/pages/models/menu.rb +24 -15
- data/lib/hancock/pages/models/mongoid/block.rb +13 -0
- data/lib/hancock/pages/models/mongoid/blockset.rb +3 -0
- data/lib/hancock/pages/models/mongoid/menu.rb +4 -1
- data/lib/hancock/pages/models/mongoid/page.rb +19 -6
- data/lib/hancock/pages/models/page.rb +196 -90
- data/lib/hancock/pages/rails_admin_ext/hancock_connectable.rb +2 -0
- data/lib/hancock/pages/rails_admin_ext/menu.rb +11 -7
- data/lib/hancock/pages/version.rb +1 -1
- data/lib/hancock/pages/views_whitelist.rb +103 -0
- data/lib/hancock_cms_pages.rb +4 -6
- data/release.sh +1 -1
- metadata +19 -14
- data/app/helpers/hancock/pages/pages_helpers.rb +0 -2
| @@ -9,6 +9,8 @@ module Hancock::Pages | |
| 9 9 | 
             
                attr_accessor :menu_max_depth
         | 
| 10 10 |  | 
| 11 11 | 
             
                attr_accessor :seo_support
         | 
| 12 | 
            +
                attr_accessor :cache_support
         | 
| 13 | 
            +
                attr_accessor :insertions_support
         | 
| 12 14 |  | 
| 13 15 | 
             
                attr_accessor :localize
         | 
| 14 16 |  | 
| @@ -18,18 +20,39 @@ module Hancock::Pages | |
| 18 20 | 
             
                attr_accessor :user_abilities_support
         | 
| 19 21 | 
             
                attr_accessor :ra_comments_support
         | 
| 20 22 |  | 
| 23 | 
            +
                attr_accessor :renderer_lib_extends
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                attr_accessor :verbose_render
         | 
| 26 | 
            +
                attr_accessor :raven_support
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                attr_accessor :available_layouts
         | 
| 29 | 
            +
             | 
| 21 30 | 
             
                def initialize
         | 
| 22 31 | 
             
                  @menu_max_depth = 2
         | 
| 23 32 |  | 
| 24 | 
            -
                  @seo_support | 
| 33 | 
            +
                  @seo_support        = !!defined? Hancock::Seo
         | 
| 34 | 
            +
                  @cache_support      = !!defined?(Hancock::Cache)
         | 
| 35 | 
            +
                  @insertions_support = true
         | 
| 25 36 |  | 
| 26 37 | 
             
                  @localize   = Hancock.config.localize
         | 
| 27 38 |  | 
| 28 | 
            -
                  @breadcrumbs_on_rails_support = defined?(BreadcrumbsOnRails)
         | 
| 39 | 
            +
                  @breadcrumbs_on_rails_support = !!defined?(BreadcrumbsOnRails)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  @model_settings_support = !!defined?(RailsAdminModelSettings)
         | 
| 42 | 
            +
                  @user_abilities_support = !!defined?(RailsAdminUserAbilities)
         | 
| 43 | 
            +
                  @ra_comments_support = !!defined?(RailsAdminComments)
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  @renderer_lib_extends = [
         | 
| 46 | 
            +
                    # ::ActionController::Base,
         | 
| 47 | 
            +
                    ::ActionView::Helpers::TagHelper,
         | 
| 48 | 
            +
                    ::ActionView::Context
         | 
| 49 | 
            +
                  ]
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  @verbose_render = Rails.env.development? or Rails.env.test?
         | 
| 52 | 
            +
                  @raven_support = !!(Hancock.config.respond_to?(:raven_support) ? Hancock.config.raven_support : defined?(Raven))
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  @available_layouts = ["application"]
         | 
| 29 55 |  | 
| 30 | 
            -
                  @model_settings_support = defined?(RailsAdminModelSettings)
         | 
| 31 | 
            -
                  @user_abilities_support = defined?(RailsAdminUserAbilities)
         | 
| 32 | 
            -
                  @ra_comments_support = defined?(RailsAdminComments)
         | 
| 33 56 | 
             
                end
         | 
| 34 57 | 
             
              end
         | 
| 35 58 | 
             
            end
         | 
| @@ -3,6 +3,11 @@ module Hancock::Pages | |
| 3 3 | 
             
                module Pages
         | 
| 4 4 | 
             
                  extend ActiveSupport::Concern
         | 
| 5 5 |  | 
| 6 | 
            +
                  included do
         | 
| 7 | 
            +
                    include ActionView::Helpers::TagHelper
         | 
| 8 | 
            +
                    include ActionView::Context
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 6 11 | 
             
                  def show
         | 
| 7 12 | 
             
                    if @seo_page.nil? || !@seo_page.persisted?
         | 
| 8 13 | 
             
                      if !params[:id].blank? or !params[:slug].blank?
         | 
| @@ -18,6 +23,10 @@ module Hancock::Pages | |
| 18 23 | 
             
                    if Hancock::Pages.config.breadcrumbs_on_rails_support
         | 
| 19 24 | 
             
                      add_breadcrumb @seo_page.name, @seo_page.slug
         | 
| 20 25 | 
             
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    if Hancock::Pages.config.available_layouts.include?(@seo_page.layout_name)
         | 
| 28 | 
            +
                      render layout: @seo_page.layout_name
         | 
| 29 | 
            +
                    end
         | 
| 21 30 | 
             
                  end
         | 
| 22 31 |  | 
| 23 32 | 
             
                  private
         | 
| @@ -27,7 +36,7 @@ module Hancock::Pages | |
| 27 36 |  | 
| 28 37 | 
             
                  def after_initialize
         | 
| 29 38 | 
             
                  end
         | 
| 30 | 
            -
             | 
| 39 | 
            +
             | 
| 31 40 | 
             
                end
         | 
| 32 41 | 
             
              end
         | 
| 33 42 | 
             
            end
         | 
    
        data/lib/hancock/pages/engine.rb
    CHANGED
    
    | @@ -1,5 +1,64 @@ | |
| 1 1 | 
             
            module Hancock::Pages
         | 
| 2 2 | 
             
              class Engine < ::Rails::Engine
         | 
| 3 3 | 
             
                # isolate_namespace Hancock::Pages
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                # initializer "hancock_cms_pages.blocksets_settings" do
         | 
| 6 | 
            +
                #   # Write default email settings to DB so they can be changed.
         | 
| 7 | 
            +
                #
         | 
| 8 | 
            +
                #   #temp
         | 
| 9 | 
            +
                #   begin
         | 
| 10 | 
            +
                #     if Settings and Settings.table_exists?
         | 
| 11 | 
            +
                #       Settings.hancock_pages_blocks_whitelist(default: '', kind: :text, label: 'Белый список блоков')
         | 
| 12 | 
            +
                #       Settings.hancock_pages_blocks_human_names(default: '', kind: :yaml, label: 'Имена блоков')
         | 
| 13 | 
            +
                #     end
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                #     # if Settings and Settings.table_exists? and Hancock::Pages.model_settings_support
         | 
| 16 | 
            +
                #     #   Hancock::Pages::Blockset.settings.blocks_whitelist(default: '', kind: :text, label: 'Белый список блоков')
         | 
| 17 | 
            +
                #     #   Hancock::Pages::Blockset.settings.blocks_human_names(default: '', kind: :yaml, label: 'Имена блоков')
         | 
| 18 | 
            +
                #     #
         | 
| 19 | 
            +
                #     #
         | 
| 20 | 
            +
                #     #   _setting_existed = !Hancock::Cache::Fragment.settings.getnc('detecting').nil?
         | 
| 21 | 
            +
                #     #   unless _setting_existed
         | 
| 22 | 
            +
                #     #     Hancock::Pages::Blockset.settings.blocks_whitelist(kind: :text, default: '', label: 'Белый список блоков')
         | 
| 23 | 
            +
                #     #     Hancock::Pages::Blockset.settings.unload!
         | 
| 24 | 
            +
                #     #     _setting = Hancock::Pages::Blockset.settings.getnc('blocks_whitelist')
         | 
| 25 | 
            +
                #     #     if _setting
         | 
| 26 | 
            +
                #     #       _setting.for_admin = true
         | 
| 27 | 
            +
                #     #       _setting.perform_caching = false
         | 
| 28 | 
            +
                #     #       _setting.save
         | 
| 29 | 
            +
                #     #     end
         | 
| 30 | 
            +
                #     #   end
         | 
| 31 | 
            +
                #     #
         | 
| 32 | 
            +
                #     #
         | 
| 33 | 
            +
                #     #   _setting_existed = !Hancock::Cache::Fragment.settings.getnc('detecting').nil?
         | 
| 34 | 
            +
                #     #   unless _setting_existed
         | 
| 35 | 
            +
                #     #     Hancock::Pages::Blockset.settings.blocks_human_names(default: '', kind: :yaml, label: 'Имена блоков')
         | 
| 36 | 
            +
                #     #     Hancock::Pages::Blockset.settings.unload!
         | 
| 37 | 
            +
                #     #     _setting = Hancock::Pages::Blockset.settings.getnc('blocks_human_names')
         | 
| 38 | 
            +
                #     #     if _setting
         | 
| 39 | 
            +
                #     #       _setting.for_admin = true
         | 
| 40 | 
            +
                #     #       _setting.perform_caching = false
         | 
| 41 | 
            +
                #     #       _setting.save
         | 
| 42 | 
            +
                #     #     end
         | 
| 43 | 
            +
                #     #   end
         | 
| 44 | 
            +
                #     #
         | 
| 45 | 
            +
                #     # end
         | 
| 46 | 
            +
                #   rescue
         | 
| 47 | 
            +
                #   end
         | 
| 48 | 
            +
                # end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                config.after_initialize do
         | 
| 51 | 
            +
                  # Write default email settings to DB so they can be changed.
         | 
| 52 | 
            +
                  begin
         | 
| 53 | 
            +
                    if Settings and Settings.table_exists?
         | 
| 54 | 
            +
                      Settings.hancock_pages_blocks_whitelist(default: '', kind: :text, label: 'Белый список блоков') unless RailsAdminSettings::Setting.ns("main").where(key: "hancock_pages_blocks_whitelist").exists?
         | 
| 55 | 
            +
                      Settings.hancock_pages_blocks_human_names(default: '', kind: :yaml, label: 'Имена блоков') unless RailsAdminSettings::Setting.ns("main").where(key: "hancock_pages_blocks_human_names").exists?
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                      Settings.ns('admin').hancock_pages_blocks_blacklist(default: '', kind: :text, label: 'Черный список блоков') unless RailsAdminSettings::Setting.ns("admin").where(key: "hancock_pages_blocks_blacklist").exists?
         | 
| 58 | 
            +
                    end
         | 
| 59 | 
            +
                  rescue
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 4 63 | 
             
              end
         | 
| 5 64 | 
             
            end
         | 
| @@ -11,7 +11,8 @@ module Hancock::Pages | |
| 11 11 | 
             
                        translates :name
         | 
| 12 12 | 
             
                      end
         | 
| 13 13 |  | 
| 14 | 
            -
                      has_many : | 
| 14 | 
            +
                      has_many :blocks, class_name: "Hancock::Pages::Blockset", inverse_of: :blockset
         | 
| 15 | 
            +
                      accepts_nested_attributes_for :blocks, allow_destroy: true
         | 
| 15 16 | 
             
                    end
         | 
| 16 17 | 
             
                  end
         | 
| 17 18 | 
             
                end
         | 
| @@ -6,6 +6,10 @@ module Hancock::Pages | |
| 6 6 | 
             
                  include Hancock::Enableable
         | 
| 7 7 | 
             
                  include ManualSlug
         | 
| 8 8 |  | 
| 9 | 
            +
                  if Hancock::Pages.config.insertions_support
         | 
| 10 | 
            +
                    include Hancock::InsertionField
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 9 13 | 
             
                  include Hancock::Pages.orm_specific('Block')
         | 
| 10 14 |  | 
| 11 15 | 
             
                  included do
         | 
| @@ -21,6 +25,93 @@ module Hancock::Pages | |
| 21 25 | 
             
                    after_initialize do
         | 
| 22 26 | 
             
                      self.file_pathname = Pathname.new(file_path) unless file_path.nil?
         | 
| 23 27 | 
             
                    end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    def can_render?
         | 
| 30 | 
            +
                      Hancock::Pages::can_render_in_block?(self.file_path)
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    if Hancock::Pages.config.insertions_support
         | 
| 34 | 
            +
                      # insertions_for(:content)
         | 
| 35 | 
            +
                      insertions_for(:content_html)
         | 
| 36 | 
            +
                      alias :block_content :page_content
         | 
| 37 | 
            +
                      alias :block_content_html :page_content_html
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                    def block_content(clear_insertions = true)
         | 
| 40 | 
            +
                      if clear_insertions.is_a?(Hash)
         | 
| 41 | 
            +
                        clear_insertions = clear_insertions[:clear_insertions]
         | 
| 42 | 
            +
                      end
         | 
| 43 | 
            +
                      if @content_used.nil?
         | 
| 44 | 
            +
                        if content.nil?
         | 
| 45 | 
            +
                          @content_used = true
         | 
| 46 | 
            +
                          ''
         | 
| 47 | 
            +
                        else
         | 
| 48 | 
            +
                          # content.gsub(/\{\{(.*?)\}\}/) do
         | 
| 49 | 
            +
                          # {{"some_text"}} #temporary disabled - need tests
         | 
| 50 | 
            +
                          # _content = content.gsub(/\{\{(['"])(.*?)(\1)\}\}/) do
         | 
| 51 | 
            +
                          #   $2
         | 
| 52 | 
            +
                          # end.gsub(/(\{\{(([^\.]*?)\.)?(.*?)\}\})/) do
         | 
| 53 | 
            +
                          _content = content.gsub(/(\{\{(([^\.]*?)\.)?(.*?)\}\})/) do
         | 
| 54 | 
            +
                            if $4 == "FILE" and $3.blank?
         | 
| 55 | 
            +
                              clear_insertions ? "" : $1
         | 
| 56 | 
            +
                            elsif $4 =~ /\ABS\|(.*?)\Z/ and $3.blank?
         | 
| 57 | 
            +
                              clear_insertions ? "" : $1
         | 
| 58 | 
            +
                            elsif $3 == "self" and !$4.blank?
         | 
| 59 | 
            +
                              if clear_insertions
         | 
| 60 | 
            +
                                ""
         | 
| 61 | 
            +
                              elsif Hancock::Pages.config.insertions_support
         | 
| 62 | 
            +
                                get_insertion($4)
         | 
| 63 | 
            +
                              else
         | 
| 64 | 
            +
                                $1
         | 
| 65 | 
            +
                              end
         | 
| 66 | 
            +
                            else
         | 
| 67 | 
            +
                              (Settings and !$4.blank? and $3 != "self") ? Settings.ns($3).get($4).val : "" #temp
         | 
| 68 | 
            +
                            end
         | 
| 69 | 
            +
                          end
         | 
| 70 | 
            +
                          @content_used = true
         | 
| 71 | 
            +
                          _content
         | 
| 72 | 
            +
                        end
         | 
| 73 | 
            +
                      else
         | 
| 74 | 
            +
                        ''
         | 
| 75 | 
            +
                      end
         | 
| 76 | 
            +
                    end
         | 
| 77 | 
            +
                    def block_content_html(clear_insertions = true)
         | 
| 78 | 
            +
                      if clear_insertions.is_a?(Hash)
         | 
| 79 | 
            +
                        clear_insertions = clear_insertions[:clear_insertions]
         | 
| 80 | 
            +
                      end
         | 
| 81 | 
            +
                      if @content_html_used.nil?
         | 
| 82 | 
            +
                        if content_html.nil?
         | 
| 83 | 
            +
                          @content_html_used = true
         | 
| 84 | 
            +
                          ''
         | 
| 85 | 
            +
                        else
         | 
| 86 | 
            +
                          # content.gsub(/\{\{(.*?)\}\}/) do
         | 
| 87 | 
            +
                          # {{"some_text"}} #temporary disabled - need tests
         | 
| 88 | 
            +
                          # _content_html = content_html.gsub(/\{\{(['"])(.*?)(\1)\}\}/) do
         | 
| 89 | 
            +
                          #   $2
         | 
| 90 | 
            +
                          # end.gsub(/(\{\{(([^\.]*?)\.)?(.*?)\}\})/) do
         | 
| 91 | 
            +
                          _content_html = content_html.gsub(/(\{\{(([^\.]*?)\.)?(.*?)\}\})/) do
         | 
| 92 | 
            +
                            if $4 == "FILE" and $3.blank?
         | 
| 93 | 
            +
                              clear_insertions ? "" : $1
         | 
| 94 | 
            +
                            elsif $4 =~ /\ABS\|(.*?)\Z/ and $3.blank?
         | 
| 95 | 
            +
                              clear_insertions ? "" : $1
         | 
| 96 | 
            +
                            elsif $3 == "self" and !$4.blank?
         | 
| 97 | 
            +
                              if clear_insertions
         | 
| 98 | 
            +
                                ""
         | 
| 99 | 
            +
                              elsif Hancock::Pages.config.insertions_support
         | 
| 100 | 
            +
                                get_insertion($4)
         | 
| 101 | 
            +
                              else
         | 
| 102 | 
            +
                                $1
         | 
| 103 | 
            +
                              end
         | 
| 104 | 
            +
                            else
         | 
| 105 | 
            +
                              (Settings and !$4.blank? and $3 != "self") ? Settings.ns($3).get($4).val : "" #temp
         | 
| 106 | 
            +
                            end
         | 
| 107 | 
            +
                          end
         | 
| 108 | 
            +
                          @content_html_used = true
         | 
| 109 | 
            +
                          _content_html
         | 
| 110 | 
            +
                        end
         | 
| 111 | 
            +
                      else
         | 
| 112 | 
            +
                        ''
         | 
| 113 | 
            +
                      end
         | 
| 114 | 
            +
                    end
         | 
| 24 115 | 
             
                  end
         | 
| 25 116 |  | 
| 26 117 | 
             
                  def file_pathname_as_partial
         | 
| @@ -37,70 +128,97 @@ module Hancock::Pages | |
| 37 128 | 
             
                    self.file_pathname_for_fs.to_s
         | 
| 38 129 | 
             
                  end
         | 
| 39 130 |  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
                    end
         | 
| 48 | 
            -
                    if @content_used.nil?
         | 
| 49 | 
            -
                      @content_used = true
         | 
| 50 | 
            -
                      if content.nil?
         | 
| 51 | 
            -
                        ''
         | 
| 131 | 
            +
                  def rails_admin_label
         | 
| 132 | 
            +
                    if !self.name.blank?
         | 
| 133 | 
            +
                      self.name
         | 
| 134 | 
            +
                    elsif self.render_file and !self.file_path.blank?
         | 
| 135 | 
            +
                      _human_name = Hancock::Pages.whitelist_human_names[self.file_path]
         | 
| 136 | 
            +
                      if _human_name.blank?
         | 
| 137 | 
            +
                        self.file_path_for_fs
         | 
| 52 138 | 
             
                      else
         | 
| 53 | 
            -
                         | 
| 54 | 
            -
                        content.gsub(/\{\{(([^\.]*?)\.)?(.*?)\}\}/) do
         | 
| 55 | 
            -
                          if $3 == "FILE" and $2.blank?
         | 
| 56 | 
            -
                            clear_insertions ? "" : $0
         | 
| 57 | 
            -
                          else
         | 
| 58 | 
            -
                            (Settings and !$3.blank?) ? Settings.ns($2).get($3).val : "" #temp
         | 
| 59 | 
            -
                          end
         | 
| 60 | 
            -
                        end
         | 
| 139 | 
            +
                        _human_name
         | 
| 61 140 | 
             
                      end
         | 
| 62 141 | 
             
                    else
         | 
| 63 | 
            -
                       | 
| 142 | 
            +
                      self.id
         | 
| 64 143 | 
             
                    end
         | 
| 65 144 | 
             
                  end
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                  def has_content?
         | 
| 147 | 
            +
                    @content_used.nil? && !content.blank?
         | 
| 148 | 
            +
                  end
         | 
| 66 149 | 
             
                  def has_content_html?
         | 
| 67 150 | 
             
                    @content_html_used.nil? && !content_html.blank?
         | 
| 68 151 | 
             
                  end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 152 | 
            +
             | 
| 153 | 
            +
                  def render_or_content_html(view = Hancock::Pages::PagesController.new, opts = {})
         | 
| 154 | 
            +
                    if view.is_a?(Hash)
         | 
| 155 | 
            +
                      view, opts = view.delete(:view) || Hancock::Pages::PagesController.new, view
         | 
| 72 156 | 
             
                    end
         | 
| 73 | 
            -
                     | 
| 74 | 
            -
                       | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
                        content_html.gsub(/\{\{(([^\.]*?)\.)?(.*?)\}\}/) do
         | 
| 80 | 
            -
                          if $3 == "FILE" and $2.blank?
         | 
| 81 | 
            -
                            clear_insertions ? "" : $0
         | 
| 82 | 
            -
                          else
         | 
| 83 | 
            -
                            (Settings and !$3.blank?) ? Settings.ns($2).get($3).val : "" #temp
         | 
| 84 | 
            -
                          end
         | 
| 157 | 
            +
                    Hancock::Pages.config.renderer_lib_extends.each do |lib_extends|
         | 
| 158 | 
            +
                      unless view.class < lib_extends
         | 
| 159 | 
            +
                        if view.respond_to?(:prepend)
         | 
| 160 | 
            +
                          view.prepend lib_extends
         | 
| 161 | 
            +
                        else
         | 
| 162 | 
            +
                          view.extend lib_extends
         | 
| 85 163 | 
             
                        end
         | 
| 86 164 | 
             
                      end
         | 
| 87 | 
            -
                    else
         | 
| 88 | 
            -
                      ''
         | 
| 89 165 | 
             
                    end
         | 
| 90 | 
            -
                  end
         | 
| 91 166 |  | 
| 92 | 
            -
                  def render_or_content_html(view, opts = {})
         | 
| 93 | 
            -
                    if view.is_a?(Hash)
         | 
| 94 | 
            -
                      view, opts = view.delete(:view), view
         | 
| 95 | 
            -
                    end
         | 
| 96 167 | 
             
                    ret = ""
         | 
| 168 | 
            +
                    hancock_env = {block: self, called_from: [{object: self, method: :render_or_content_html}]}
         | 
| 169 | 
            +
                    hancock_env[:called_from].unshift(opts.delete(:called_from)) if opts and opts[:called_from].present?
         | 
| 170 | 
            +
                    locals = {}
         | 
| 171 | 
            +
                    locals[:hancock_env] = hancock_env
         | 
| 172 | 
            +
             | 
| 97 173 | 
             
                    if self.render_file and !self.file_path.blank?
         | 
| 98 | 
            -
                      opts.merge!(partial: self.file_path, locals:  | 
| 99 | 
            -
                      ret = view. | 
| 174 | 
            +
                      opts.merge!(partial: self.file_path, locals: locals)
         | 
| 175 | 
            +
                      # ret = view.render_to_string(opts) rescue self.content_html.html_safe
         | 
| 176 | 
            +
                      ret = begin
         | 
| 177 | 
            +
                        view.render_to_string(opts) if can_render?
         | 
| 178 | 
            +
                      rescue Exception => exception
         | 
| 179 | 
            +
                        if Hancock::Pages.config.verbose_render
         | 
| 180 | 
            +
                          Rails.logger.error exception.message
         | 
| 181 | 
            +
                          Rails.logger.error exception.backtrace.join("\n")
         | 
| 182 | 
            +
                          puts exception.message
         | 
| 183 | 
            +
                          puts exception.backtrace.join("\n")
         | 
| 184 | 
            +
                        end
         | 
| 185 | 
            +
                        Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 186 | 
            +
                        self.content_html.html_safe
         | 
| 187 | 
            +
                      end
         | 
| 100 188 | 
             
                    else
         | 
| 101 | 
            -
                      opts.merge!(partial: self.file_path, locals:  | 
| 189 | 
            +
                      opts.merge!(partial: self.file_path, locals: locals)
         | 
| 190 | 
            +
                      # ret = self.block_content_html(false).gsub(/(\{\{(([^\.]*?)\.)?(.*?)\}\})/) do
         | 
| 102 191 | 
             
                      ret = self.block_content_html(false).gsub("{{FILE}}") do
         | 
| 103 | 
            -
                        view.render(opts) rescue nil
         | 
| 192 | 
            +
                        # view.render(opts) rescue nil
         | 
| 193 | 
            +
                        begin
         | 
| 194 | 
            +
                          view.render(opts) if can_render?
         | 
| 195 | 
            +
                        rescue Exception => exception
         | 
| 196 | 
            +
                          if Hancock::Pages.config.verbose_render
         | 
| 197 | 
            +
                            Rails.logger.error exception.message
         | 
| 198 | 
            +
                            Rails.logger.error exception.backtrace.join("\n")
         | 
| 199 | 
            +
                            puts exception.message
         | 
| 200 | 
            +
                            puts exception.backtrace.join("\n")
         | 
| 201 | 
            +
                          end
         | 
| 202 | 
            +
                          Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 203 | 
            +
                          nil
         | 
| 204 | 
            +
                        end
         | 
| 205 | 
            +
                      end.gsub(/\{\{BS\|(.*?)\}\}/) do
         | 
| 206 | 
            +
                        bs = Hancock::Pages::Blockset.enabled.where(name: $1).first
         | 
| 207 | 
            +
                        # view.render_blockset(bs, called_from: :render_or_content_html) rescue nil if bs
         | 
| 208 | 
            +
                        if bs
         | 
| 209 | 
            +
                          begin
         | 
| 210 | 
            +
                            view.render_blockset(bs, called_from: {object: self, method: :render_or_content_html})
         | 
| 211 | 
            +
                          rescue Exception => exception
         | 
| 212 | 
            +
                            if Hancock::Pages.config.verbose_render
         | 
| 213 | 
            +
                              Rails.logger.error exception.message
         | 
| 214 | 
            +
                              Rails.logger.error exception.backtrace.join("\n")
         | 
| 215 | 
            +
                              puts exception.message
         | 
| 216 | 
            +
                              puts exception.backtrace.join("\n")
         | 
| 217 | 
            +
                            end
         | 
| 218 | 
            +
                            Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 219 | 
            +
                            nil
         | 
| 220 | 
            +
                          end
         | 
| 221 | 
            +
                        end
         | 
| 104 222 | 
             
                      end.html_safe
         | 
| 105 223 | 
             
                    end
         | 
| 106 224 | 
             
                    if use_wrapper
         | 
| @@ -111,25 +229,86 @@ module Hancock::Pages | |
| 111 229 | 
             
                      ret = view.content_tag wrapper_tag, ret, _attrs
         | 
| 112 230 | 
             
                    end
         | 
| 113 231 | 
             
                    ret = yield ret if block_given?
         | 
| 114 | 
            -
                    return ret
         | 
| 232 | 
            +
                    return (ret.is_a?(Array) ? ret.join.html_safe : ret)
         | 
| 233 | 
            +
                    # return ret
         | 
| 115 234 | 
             
                  end
         | 
| 116 235 |  | 
| 117 | 
            -
                  def render_or_content(view, opts = {})
         | 
| 236 | 
            +
                  def render_or_content(view = Hancock::Pages::PagesController.new, opts = {})
         | 
| 118 237 | 
             
                    if view.is_a?(Hash)
         | 
| 119 | 
            -
                      view, opts = view.delete(:view), view
         | 
| 238 | 
            +
                      view, opts = view.delete(:view) || Hancock::Pages::PagesController.new, view
         | 
| 239 | 
            +
                    end
         | 
| 240 | 
            +
                    Hancock::Pages.config.renderer_lib_extends.each do |lib_extends|
         | 
| 241 | 
            +
                      unless view.class < lib_extends
         | 
| 242 | 
            +
                        if view.respond_to?(:prepend)
         | 
| 243 | 
            +
                          view.prepend lib_extends
         | 
| 244 | 
            +
                        else
         | 
| 245 | 
            +
                          view.extend lib_extends
         | 
| 246 | 
            +
                        end
         | 
| 247 | 
            +
                      end
         | 
| 120 248 | 
             
                    end
         | 
| 249 | 
            +
             | 
| 121 250 | 
             
                    ret = ""
         | 
| 251 | 
            +
                    hancock_env = {block: self, called_from: [{object: self, method: :render_or_content}]}
         | 
| 252 | 
            +
                    hancock_env[:called_from].unshift(opts.delete(:called_from)) if opts and opts[:called_from].present?
         | 
| 253 | 
            +
                    locals = {}
         | 
| 254 | 
            +
                    locals[:hancock_env] = hancock_env
         | 
| 255 | 
            +
             | 
| 122 256 | 
             
                    unless self.file_path.blank?
         | 
| 123 | 
            -
                      opts.merge!(partial: self.file_path, locals:  | 
| 124 | 
            -
             | 
| 257 | 
            +
                      opts.merge!(partial: self.file_path, locals: locals)
         | 
| 258 | 
            +
             | 
| 259 | 
            +
                      # ret = view.render_to_string(opts) rescue self.content
         | 
| 260 | 
            +
                      ret = begin
         | 
| 261 | 
            +
                        view.render_to_string(opts) if can_render?
         | 
| 262 | 
            +
                      rescue Exception => exception
         | 
| 263 | 
            +
                        if Hancock::Pages.config.verbose_render
         | 
| 264 | 
            +
                          Rails.logger.error exception.message
         | 
| 265 | 
            +
                          Rails.logger.error exception.backtrace.join("\n")
         | 
| 266 | 
            +
                          puts exception.message
         | 
| 267 | 
            +
                          puts exception.backtrace.join("\n")
         | 
| 268 | 
            +
                        end
         | 
| 269 | 
            +
                        Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 270 | 
            +
                        self.content
         | 
| 271 | 
            +
                      end
         | 
| 272 | 
            +
                      # ret = view.render(opts) rescue self.content
         | 
| 125 273 | 
             
                    else
         | 
| 126 | 
            -
                      opts.merge!(partial: self.file_path, locals:  | 
| 274 | 
            +
                      opts.merge!(partial: self.file_path, locals: locals)
         | 
| 127 275 | 
             
                      ret = self.block_content(false).gsub("{{FILE}}") do
         | 
| 128 | 
            -
                        view. | 
| 276 | 
            +
                        # view.render_to_string(opts) rescue nil
         | 
| 277 | 
            +
                        begin
         | 
| 278 | 
            +
                          view.render_to_string(opts) if can_render?
         | 
| 279 | 
            +
                        rescue Exception => exception
         | 
| 280 | 
            +
                          if Hancock::Pages.config.verbose_render
         | 
| 281 | 
            +
                            Rails.logger.error exception.message
         | 
| 282 | 
            +
                            Rails.logger.error exception.backtrace.join("\n")
         | 
| 283 | 
            +
                            puts exception.message
         | 
| 284 | 
            +
                            puts exception.backtrace.join("\n")
         | 
| 285 | 
            +
                          end
         | 
| 286 | 
            +
                          Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 287 | 
            +
                          nil
         | 
| 288 | 
            +
                        end
         | 
| 289 | 
            +
                        # view.render(opts) rescue nil
         | 
| 290 | 
            +
                      end.gsub(/\{\{BS\|(.*?)\}\}/) do
         | 
| 291 | 
            +
                        bs = Hancock::Pages::Blockset.enabled.where(name: $1).first
         | 
| 292 | 
            +
                        # view.render_blockset(bs, called_from: :render_or_content) rescue nil if bs
         | 
| 293 | 
            +
                        if bs
         | 
| 294 | 
            +
                          begin
         | 
| 295 | 
            +
                            view.render_blockset(bs, called_from: {object: self, method: :render_or_content})
         | 
| 296 | 
            +
                          rescue Exception => exception
         | 
| 297 | 
            +
                            if Hancock::Pages.config.verbose_render
         | 
| 298 | 
            +
                              Rails.logger.error exception.message
         | 
| 299 | 
            +
                              Rails.logger.error exception.backtrace.join("\n")
         | 
| 300 | 
            +
                              puts exception.message
         | 
| 301 | 
            +
                              puts exception.backtrace.join("\n")
         | 
| 302 | 
            +
                            end
         | 
| 303 | 
            +
                            Raven.capture_exception(exception) if Hancock::Pages.config.raven_support
         | 
| 304 | 
            +
                            nil
         | 
| 305 | 
            +
                          end
         | 
| 306 | 
            +
                        end
         | 
| 129 307 | 
             
                      end
         | 
| 130 308 | 
             
                    end
         | 
| 131 309 | 
             
                    ret = yield ret if block_given?
         | 
| 132 | 
            -
                    return ret
         | 
| 310 | 
            +
                    return (ret.is_a?(Array) ? ret.join.html_safe : ret)
         | 
| 311 | 
            +
                    # return ret
         | 
| 133 312 | 
             
                  end
         | 
| 134 313 |  | 
| 135 314 | 
             
                  def file_fullpath(with_ext = false, ext = ".html.slim")
         |