class LangPage < ActiveRecord::Base
  belongs_to :lang_site
  belongs_to :page
  
  belongs_to :without_text_image_file, :class_name => "ImageFile"
  
  #attr_accessor :force_validation
  validates :title, :presence => true #, :if => :force_validation
  
  
  
  def html
   
    
    
    

    @menu_item =self.page.menu_item
    
    if @menu_item
    @lang = self.lang_site
    
    
    #view = ActionView::Base.new('app/views/public/articles', {:lang => @lang, :lang_article => self, :article => self.article },  ActionController::Base.new)
    #puts view.render(file: '_show.html.haml')
    render_anywhere 'public/menu_items/_show', {:lang => @lang, :menu_item => @menu_item, :page_images_credits => [] }
    #ApplicationController.new.render_to_string(
    #  :template => 'public/articles/_show',
    #  :locals =>  {:@lang => @lang, :@lang_article => self, :@article => self.article }
    #)
  else
    ""
    end
  end
  
  
  def render_anywhere(partial, assigns= {})
    view = ActionView::Base.new(Rails.configuration.paths['app/views'], assigns)
    view.extend ApplicationHelper
    
    view.class_eval do
      include Rails.application.routes.url_helpers
      include ApplicationHelper
      include IconHelper
      include TranslationHelper
      def protect_against_forgery?
        false
      end
    end
    
    view.render(:template => partial, :layout => false)
    
    
  end
  
  
  
end
