<commit_before>class CategoriesController < ApplicationController
  before_filter :login_required, :except => :index
  cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]

  # GET /categories
  # GET /categories.xml
  def index
    @top_level_categories = Category.find(:all, :conditions => "parent_id is NULL").sort_by {|a| a.name}
    @categories = Category.find(:all).sort_by { |a| a.long_name }

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

  # GET /categories/1
  # GET /categories/1.xml
  def show
    @category = Category.find(params[:id])

    respond_to do |format|
      format.html do
        @offers = @category.offers
      end
      format.json { render :json => @category.as_json(:only => [:id,:name], :include => {:offers => {:methods => [:icon], :only => [:id,:name,:icon,:description]}}) }
      format.xml  { render :xml => @category.to_xml(:only => [:id,:name], :include => {:offers => {:methods => [:icon], :only => [:id,:name,:icon,:description]}}) }
    end
  end

  # GET /categories/new
  # GET /categories/new.xml
  def new
    @category = Category.new
    @all_categories = Category.by_long_name

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

  # GET /categories/1/edit
  def edit
    @category = Category.find(params[:id])
    @all_categories = Category.by_long_name
  end

  # POST /categories
  # POST /categories.xml
  def create
    @category = Category.new(params[:category])

    respond_to do |format|
      if can?(:create, @category) && @category.save
        flash[:success] = t('success_category_created')
        format.html { redirect_to(@category) }
        format.xml  { render :xml => @category, :status => :created, :location => @category }
      else
        @category = Category.new
        @all_categories = Category.by_long_name
        format.html { render :action => "new" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /categories/1
  # PUT /categories/1.xml
  def update
    @category = Category.find(params[:id])

    respond_to do |format|
      if can?(:update, @category) && @category.update_attributes(params[:category])
        flash[:notice] = t('notice_category_updated')
        format.html { redirect_to(@category) }
        format.xml  { head :ok }
      else
        @category = Category.find(params[:id])
        @all_categories = Category.by_long_name
        format.html { render :action => "edit" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /categories/1
  # DELETE /categories/1.xml
  def destroy
    @category = Category.find(params[:id])

    respond_to do |format|
      if can?(:destroy, @category)
        @category.destroy
        format.html { redirect_to(categories_url) }
        format.xml  { head :ok }
      else
        @top_level_categories = Category.find(:all, :conditions => "parent_id is NULL").sort_by {|a| a.name}
        @categories = Category.find(:all).sort_by { |a| a.long_name }
        format.html { render :action => "index" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end
end
<commit_msg>Reverted json/xml formatting to initial state before issue 278 as per request by Tom<commit_after>class CategoriesController < ApplicationController
  before_filter :login_required, :except => :index
  cache_sweeper :category_sweeper, :only => [:create, :update, :destroy]

  # GET /categories
  # GET /categories.xml
  def index
    @top_level_categories = Category.find(:all, :conditions => "parent_id is NULL").sort_by {|a| a.name}
    @categories = Category.find(:all).sort_by { |a| a.long_name }

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

  # GET /categories/1
  # GET /categories/1.xml
  def show
    @category = Category.find(params[:id])

    respond_to do |format|
      format.html do
        @offers = @category.offers
      end
    #WARNING: Semantics of html and json/xml formatting are different!
    #html renders offers for the skillbank (requested by issue 278, while
    #Tom requires json/xml to stay the way it was as per comment https://github.com/oscurrency/oscurrency/pull/377#issuecomment-15572787
      format.json { render :json => @category.as_json(:only => [:id,:name], :include => {:people => {:methods => [:icon, :notifications], :only => [:id,:name,:icon,:notifications,:deactivated]}}) }
      format.xml { render :xml => @category.to_xml(:only => [:id,:name], :include => {:people => {:methods => [:icon, :notifications], :only => [:id,:name,:icon,:notifications,:deactivated]}}) }
    end
  end

  # GET /categories/new
  # GET /categories/new.xml
  def new
    @category = Category.new
    @all_categories = Category.by_long_name

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

  # GET /categories/1/edit
  def edit
    @category = Category.find(params[:id])
    @all_categories = Category.by_long_name
  end

  # POST /categories
  # POST /categories.xml
  def create
    @category = Category.new(params[:category])

    respond_to do |format|
      if can?(:create, @category) && @category.save
        flash[:success] = t('success_category_created')
        format.html { redirect_to(@category) }
        format.xml  { render :xml => @category, :status => :created, :location => @category }
      else
        @category = Category.new
        @all_categories = Category.by_long_name
        format.html { render :action => "new" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /categories/1
  # PUT /categories/1.xml
  def update
    @category = Category.find(params[:id])

    respond_to do |format|
      if can?(:update, @category) && @category.update_attributes(params[:category])
        flash[:notice] = t('notice_category_updated')
        format.html { redirect_to(@category) }
        format.xml  { head :ok }
      else
        @category = Category.find(params[:id])
        @all_categories = Category.by_long_name
        format.html { render :action => "edit" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /categories/1
  # DELETE /categories/1.xml
  def destroy
    @category = Category.find(params[:id])

    respond_to do |format|
      if can?(:destroy, @category)
        @category.destroy
        format.html { redirect_to(categories_url) }
        format.xml  { head :ok }
      else
        @top_level_categories = Category.find(:all, :conditions => "parent_id is NULL").sort_by {|a| a.name}
        @categories = Category.find(:all).sort_by { |a| a.long_name }
        format.html { render :action => "index" }
        format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1369824951375382, 'fraction_numerical': 0.004306751875520978, 'mean_word_length': 2.9403393541324574, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 49}, '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': '3211375', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2237, 'n_words': 536}