<commit_before>class FrontPagesController < ApplicationController
  
  layout 'admin'
  
  skip_before_filter :require_user, :only => :show
  before_filter :load_access_token, :except => :show

  # GET /front_pages
  # GET /front_pages.xml
  def index
    @front_pages = @account.front_pages.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @front_pages }
    end
  end

  # GET /front_pages/1
  # GET /front_pages/1.xml
  def show
    @front_page = @account.front_pages.find(params[:id])
    @current_template = @front_page.template
    
    # Build query of only the necessary ids
    schema_ids = Array.new
    @front_page.schema.each_key do |item|
      schema_ids += @front_page.schema[item]['ids']
    end
    article_resources = Article.find(:all, :ids => schema_ids, :account_id => @account.account_resource_id )
    
    # Recontruct front page schema as hash keyed by entity name
    data_for_render = {}
    schema_articles = {}
    article_resources.each do |article|
      schema_articles.merge!(article.id => article)
    end
    @front_page.schema.each_key do |item|
      item_array = @front_page.schema[item]['ids'].collect{ |i| schema_articles[i] }
      data_for_render.merge!( item => item_array )
    end
    
    page_html = @current_template.parsed_code.render(data_for_render)
    if @current_template.current_layout
      render :text => @current_template.current_layout.parsed_code.render('page_content' => page_html )
    else  
      render :text => page_html
    end
  end

  # GET /front_pages/new
  # GET /front_pages/new.xml
  def new
      respond_to do |format|
        format.html
        format.js
      end
  end

  # GET /front_pages/1/edit
  def edit
    @front_page = @account.front_pages.find(params[:id])
    page = params[:page] || 1
    schema_ids = Array.new
    @front_page.schema.each_key do |item|
      schema_ids += @front_page.schema[item]['ids'].compact unless @front_page.schema[item]['ids'].blank?<commit_msg>bugfix: handle the case where we get empty schema id's<commit_after>class FrontPagesController < ApplicationController
  
  layout 'admin'
  
  skip_before_filter :require_user, :only => :show
  before_filter :load_access_token, :except => :show

  # GET /front_pages
  # GET /front_pages.xml
  def index
    @front_pages = @account.front_pages.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @front_pages }
    end
  end

  # GET /front_pages/1
  # GET /front_pages/1.xml
  def show
    @front_page = @account.front_pages.find(params[:id])
    @current_template = @front_page.template
    
    # Build query of only the necessary ids
    schema_ids = Array.new
    @front_page.schema.each_key do |item|
      schema_ids += @front_page.schema[item]['ids']
    end    
    
    article_resources = Article.find(:all, :ids => schema_ids.reject{ |i| i.blank? }, :account_id => @account.account_resource_id)
  
    # Recontruct front page schema as hash keyed by entity name
    data_for_render = {}
    schema_articles = {}
    
    debugger 
    
    article_resources.each do |article|
      schema_articles.merge!(article.id => article)
    end
    
    @front_page.schema.each_key do |item|
      item_array = @front_page.schema[item]['ids'].collect{ |i| schema_articles[i] }
      data_for_render.merge!( item => item_array )
    end
    
    page_html = @current_template.parsed_code.render(data_for_render)
    if @current_template.current_layout
      render :text => @current_template.current_layout.parsed_code.render('page_content' => page_html )
    else  
      render :text => page_html
    end
  end

  # GET /front_pages/new
  # GET /front_pages/new.xml
  def new
      respond_to do |format|
        format.html
        format.js
      end
  end

  # GET /front_pages/1/edit
  def edit
    @front_page = @account.front_pages.find(params[:id])
    page = params[:page] || 1
    schema_ids = Array.new
    @front_page.schema.each_key do |item|
      schema_ids += @front_page.schema[item]['ids'].compact unless @front_page.schema[item]['ids'].blank?
{'fraction_non_alphanumeric': 0.10965867828612927, 'fraction_numerical': 0.0019365770999757927, 'mean_word_length': 3.1155378486055776, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '2353874', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1345, 'n_words': 285}