<commit_before>module Storytime
  module ApplicationHelper

    def logged_in_storytime_user?
      user_signed_in? && current_user.respond_to?(:storytime_user?) && current_user.storytime_user?(@site)
    end

    def dashboard_nav_site_path(site)
      site.nil? || site.new_record? ? storytime.new_dashboard_site_path : storytime.edit_dashboard_site_path(site)
    end

    def dashboard_nav_class
      if @hide_nav
        "off-canvas-left"
      elsif dashboard_controller
        "off-canvas-left-sm absolute"
      else
        "off-canvas-left"
      end
    end

    def active_nav_item_class(controller, type = nil)
      return if ["storytime/pages", "storytime/posts"].include? params[:controller]
      
      current_controller = params[:controller].split("/").last

      'class="active"'.html_safe if controller == current_controller
    end

    def active_admin_model_class(model)
      'active' if params[:controller] == 'storytime/dashboard/admin' && model_name == model
    end

    def delete_resource_link(resource, href = nil, remote = true)
      humanized_resource_name = resource.class.to_s.split('::').last.underscore.humanize.downcase
      resource_name = resource.class.to_s.downcase.split("::").last

      opts = {
        id: "delete_#{resource_name}_#{resource.id}", 
        class: "btn btn-danger btn-outline btn-xs btn-delete-resource delete-#{resource_name}-button", 
        data: { confirm: I18n.t('common.are_you_sure_you_want_to_delete', resource_name: humanized_resource_name), resource_id: resource.id, resource_type: resource_name },
        method: :delete
      }

      if remote
        opts[:remote] = true
      end
      
      link_to content_tag(:i, "", class: "icon-st-icons-trash"), href || resource, opts
    end
    
    def tag_cloud(tags, classes)
      max = tags.sort_by(&:count).last
      tags.each do |tag|
        index = tag.count.to_f / max.count * (classes.size - 1)
        yield(tag, classes[index.round])
      end
    end

    def render_comments
      if Storytime.disqus_forum_shortname.present?
        render "storytime/comments/disqus"
      elsif Storytime.discourse_name.present?<commit_msg>Use site for disqus and discourse names<commit_after>module Storytime
  module ApplicationHelper

    def logged_in_storytime_user?
      user_signed_in? && current_user.respond_to?(:storytime_user?) && current_user.storytime_user?(@site)
    end

    def dashboard_nav_site_path(site)
      site.nil? || site.new_record? ? storytime.new_dashboard_site_path : storytime.edit_dashboard_site_path(site)
    end

    def dashboard_nav_class
      if @hide_nav
        "off-canvas-left"
      elsif dashboard_controller
        "off-canvas-left-sm absolute"
      else
        "off-canvas-left"
      end
    end

    def active_nav_item_class(controller, type = nil)
      return if ["storytime/pages", "storytime/posts"].include? params[:controller]
      
      current_controller = params[:controller].split("/").last

      'class="active"'.html_safe if controller == current_controller
    end

    def active_admin_model_class(model)
      'active' if params[:controller] == 'storytime/dashboard/admin' && model_name == model
    end

    def delete_resource_link(resource, href = nil, remote = true)
      humanized_resource_name = resource.class.to_s.split('::').last.underscore.humanize.downcase
      resource_name = resource.class.to_s.downcase.split("::").last

      opts = {
        id: "delete_#{resource_name}_#{resource.id}", 
        class: "btn btn-danger btn-outline btn-xs btn-delete-resource delete-#{resource_name}-button", 
        data: { confirm: I18n.t('common.are_you_sure_you_want_to_delete', resource_name: humanized_resource_name), resource_id: resource.id, resource_type: resource_name },
        method: :delete
      }

      if remote
        opts[:remote] = true
      end
      
      link_to content_tag(:i, "", class: "icon-st-icons-trash"), href || resource, opts
    end
    
    def tag_cloud(tags, classes)
      max = tags.sort_by(&:count).last
      tags.each do |tag|
        index = tag.count.to_f / max.count * (classes.size - 1)
        yield(tag, classes[index.round])
      end
    end

    def render_comments
      if @site.disqus_forum_shortname.present?
        render "storytime/comments/disqus"
      elsif @site.discourse_name.present?
{'fraction_non_alphanumeric': 0.11141678129298486, 'fraction_numerical': 0.001375515818431912, 'mean_word_length': 3.1044214487300095, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968341', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1348, 'n_words': 253}