<commit_before>require_dependency "birdses/application_controller"

module Birdses
  class PagesController < ApplicationController
    before_filter :get_user

    def index
      @pages = Page.all
    end

    def new
      @page = Page.new
    end

    def create
      name    = params[:page][:name]
      content = params[:page][:raw_data]
      @page = Page.create(name, content, @user)
      redirect_to "#{pages_path}/#{name.parameterize}"
    end

    def show
      @page = Page.find_by_name(params[:id])
      render_404 unless @page
    end

    def edit
      @page = Page.find_by_name(params[:id])
      render_404 unless @page
    end

    def update
      name    = params[:id]
      content = params[:page][:raw_data]
      Page.update(name, content, @user)
      redirect_to "#{pages_path}/#{name.parameterize}"
    end

    def destroy
      Page.destroy(params[:id], @user)
      redirect_to pages_path
    end

    def preview
      md = Page.preview(params[:name], params[:md_content])
      html = md.formatted_data

      respond_to do |format|
        format.json { render :json => { :html => html } }
      end
    end

    private

    def get_user
      name  = 'Anonymous'
      email = '<EMAIL>'
      if defined?(current_user)
        # this rescue is necessary because .try?(:method) does not work on
        # `current_user`
        name  = current_user.fullname rescue 'Anonymous'
        email = current_user.email    rescue '<EMAIL>'
      end
      @user = { 'name' => name, 'email' => email }
    end

    def render_404
      respond_to do |type|
        type.html { render :template => "birdses/pages/404",
                    :layout => 'application', :status => 404 }
        type.all  { render :nothing => true, :status => 404 }
      end
    end
  end
end
<commit_msg>remove `.parameterize` calls<commit_after>require_dependency "birdses/application_controller"

module Birdses
  class PagesController < ApplicationController
    before_filter :get_user
    before_filter :set_page, only: [:show, :edit]

    def index
      @pages = Page.all
    end

    def new
      @page = Page.new
    end

    def create
      name    = params[:page][:name]
      content = params[:page][:raw_data]
      @page = Page.create(name, content, @user)
      redirect_to "#{pages_path}/#{name}"
    end

    def update
      name    = params[:id]
      content = params[:page][:raw_data]
      Page.update(name, content, @user)
      redirect_to "#{pages_path}/#{name}"
    end

    def destroy
      Page.destroy(params[:id], @user)
      redirect_to pages_path
    end

    def preview
      md = Page.preview(params[:name], params[:md_content])
      html = md.formatted_data

      respond_to do |format|
        format.json { render :json => { :html => html } }
      end
    end

    private

    def set_page
      @page = Page.find_by_name(params[:id])
      render_404 unless @page
    end

    def get_user
      name  = 'Anonymous'
      email = '<EMAIL>'
      if defined?(current_user)
        # this rescue is necessary because .try?(:method) does not work on
        # `current_user`
        name  = current_user.fullname rescue 'Anonymous'
        email = current_user.email    rescue '<EMAIL>'
      end
      @user = { 'name' => name, 'email' => email }
    end

    def render_404
      respond_to do |type|
        type.html { render :template => "birdses/pages/404",
                    :layout => 'application', :status => 404 }
        type.all  { render :nothing => true, :status => 404 }
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11210762331838565, 'fraction_numerical': 0.009248878923766817, 'mean_word_length': 2.2623400365630713, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '2968323', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1079, 'n_words': 283}