# frozen_string_literal: true class CompositeCell < Cell::Rails helper ApplicationHelper helper TestimonialsHelper helper ServicesHelper helper CustomHelper helper Sunrise::WidgetsHelper append_view_path 'app/views' append_view_path TranslationCms.root_path.join('app/views') SPECIFIC_CELLS = [ :welcome_slider, :welcome_why_choose_us, :welcome_calculator, :welcome_our_services, :welcome_our_achivements, :welcome_customers_testimonials, :company_cooperate, :company_testimonials, :company_recent_posts, :company_location, :company_values, :landing_testimonials ].freeze cache :page, expires_in: 4.hours do |options| [I18n.locale, request.path, options].join.hash end cache :full, expires_in: 4.hours do |_options| request.path.hash end SPECIFIC_CELLS.each do |cell| cache cell, expires_in: 4.hours do |options| [I18n.locale, request.path, options].join.hash end end def page(view = nil, args = {}) if view.is_a? Hash args = view view = nil end extract_args! args view ||= args[:view] if view && lookup_context.exists?("composite/#{view}") then render view: view.to_s elsif @structure && lookup_context.exists?("composite/#{@structure.try(:slug)}") render view: @structure.slug.to_s else render end end def full(args = {}) extract_args! args @parts = @structure ? @structure.children : [] render unless @parts.empty? end def welcome_slider(args = {}) extract_args! args @children = @structure.children if @structure render end def welcome_why_choose_us(args = {}) extract_args! args @children = @structure.children if @structure render if @structure end def welcome_calculator(args = {}) extract_args! args # TODO # make this shit render end def welcome_our_services(args = {}) extract_args! args @services_r = Structure.with_type(StructureType.services).first @services = @services_r.descendants.visible.shown_on_main.includes(:service_info).limit(4) if @services_r render end def welcome_our_achivements(args = {}) extract_args! args @children = @structure.children if @structure render if @structure end def welcome_customers_testimonials(args = {}) extract_args! args @testimonials = Testimonial.visible.local.past @testimonials = @testimonials.by_structure(@root.id) if @root.present? render if @testimonials.present? end def landing_testimonials(args = {}) welcome_customers_testimonials args end def company_cooperate(args = {}) extract_args! args @companies = CooperateCompany.sorted.limit(10) render if @companies.present? end def company_location(args = {}) extract_args! args @locations = CompanyLocation.includes(:phones).limit(3) render if @locations.present? end def company_testimonials(args = {}) # extract_args! args # @testimonials = Testimonial.visible.local.past # @testimonials = @testimonials.by_structure(@root.id) unless @root.blank? # render unless @testimonials.blank? welcome_customers_testimonials(args) end def company_values(args = {}) extract_args! args @children = @structure.children if @structure render if @structure end def company_recent_posts(args = {}) extract_args! args @posts = Post.past.limit(3) render unless @posts.empty? end def posts_block(args = {}) extract_args! args @title = args[:title] if args[:title].present? @posts = args[:posts] render unless @posts.empty? end protected def extract_args!(args) @structure = args[:structure] @root = args[:root_structure] end end