mirror of
https://github.com/discourse/discourse.git
synced 2025-02-13 08:25:16 +08:00
Support for non-english categories
This commit is contained in:
parent
d740d7b25f
commit
5d4efa9100
|
@ -11,15 +11,21 @@ Discourse.Utilities =
|
||||||
when 'large' then size=45
|
when 'large' then size=45
|
||||||
return size
|
return size
|
||||||
|
|
||||||
|
categoryUrlId: (category) ->
|
||||||
|
return "" unless category
|
||||||
|
id = Em.get(category, 'id')
|
||||||
|
slug = Em.get(category, 'slug')
|
||||||
|
return "#{id}-category" if (!slug) or slug.isBlank()
|
||||||
|
slug
|
||||||
|
|
||||||
# Create a badge like category link
|
# Create a badge like category link
|
||||||
categoryLink: (category) ->
|
categoryLink: (category) ->
|
||||||
return "" unless category
|
return "" unless category
|
||||||
|
|
||||||
slug = Em.get(category, 'slug')
|
|
||||||
color = Em.get(category, 'color')
|
color = Em.get(category, 'color')
|
||||||
name = Em.get(category, 'name')
|
name = Em.get(category, 'name')
|
||||||
|
|
||||||
"<a href=\"/category/#{slug}\" class=\"badge-category excerptable\" data-excerpt-size=\"medium\" style=\"background-color: ##{color}\">#{name}</a>"
|
"<a href=\"/category/#{@categoryUrlId(category)}\" class=\"badge-category excerptable\" data-excerpt-size=\"medium\" style=\"background-color: ##{color}\">#{name}</a>"
|
||||||
|
|
||||||
avatarUrl: (username, size, template)->
|
avatarUrl: (username, size, template)->
|
||||||
return "" unless username
|
return "" unless username
|
||||||
|
|
|
@ -3,11 +3,14 @@ window.Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend
|
||||||
|
|
||||||
slug = Em.get(model, 'slug')
|
slug = Em.get(model, 'slug')
|
||||||
category = Discourse.get('site.categories').findProperty('slug', slug)
|
category = Discourse.get('site.categories').findProperty('slug', slug)
|
||||||
|
category ||= Discourse.get('site.categories').findProperty('id', parseInt(slug))
|
||||||
category ||= Discourse.Category.create(name: slug, slug: slug)
|
category ||= Discourse.Category.create(name: slug, slug: slug)
|
||||||
|
|
||||||
listController = @controllerFor('list')
|
listController = @controllerFor('list')
|
||||||
listController.set('filterMode', "category/#{category.get('slug')}")
|
|
||||||
listController.load("category/#{category.get('slug')}").then (topicList) =>
|
urlId = Discourse.Utilities.categoryUrlId(category)
|
||||||
|
listController.set('filterMode', "category/#{urlId}")
|
||||||
|
listController.load("category/#{urlId}").then (topicList) =>
|
||||||
listController.set('canCreateTopic', topicList.get('can_create_topic'))
|
listController.set('canCreateTopic', topicList.get('can_create_topic'))
|
||||||
listController.set('category',category)
|
listController.set('category',category)
|
||||||
@controllerFor('listTopics').set('content', topicList)
|
@controllerFor('listTopics').set('content', topicList)
|
||||||
|
|
|
@ -32,7 +32,7 @@ window.Discourse.EditCategoryView = window.Discourse.ModalBodyView.extend
|
||||||
|
|
||||||
saveSuccess: (result) ->
|
saveSuccess: (result) ->
|
||||||
$('#discourse-modal').modal('hide')
|
$('#discourse-modal').modal('hide')
|
||||||
window.location = "/category/#{result.category.slug}"
|
window.location = "/category/#{Discourse.Utilities.categoryUrlId(result.category)}"
|
||||||
|
|
||||||
saveCategory: ->
|
saveCategory: ->
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class ListController < ApplicationController
|
||||||
if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name
|
if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name
|
||||||
list = query.list_uncategorized
|
list = query.list_uncategorized
|
||||||
else
|
else
|
||||||
category = Category.where(slug: params[:category]).includes(:featured_users).first
|
category = Category.where("slug = ? or id = ?", params[:category], params[:category].to_i).includes(:featured_users).first
|
||||||
guardian.ensure_can_see!(category)
|
guardian.ensure_can_see!(category)
|
||||||
list = query.list_category(category)
|
list = query.list_category(category)
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,15 @@ describe ListController do
|
||||||
|
|
||||||
it { should respond_with(:success) }
|
it { should respond_with(:success) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a link that includes an id' do
|
||||||
|
before do
|
||||||
|
xhr :get, :category, category: "#{category.slug}-#{category.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should respond_with(:success) }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'uncategorized' do
|
context 'uncategorized' do
|
||||||
|
|
|
@ -2,3 +2,4 @@ Fabricator(:category) do
|
||||||
name 'Amazing Category'
|
name 'Amazing Category'
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
describe "Discourse.Utilities", ->
|
describe "Discourse.Utilities", ->
|
||||||
|
|
||||||
|
|
||||||
|
describe "categoryUrlId", ->
|
||||||
|
|
||||||
|
it "returns the slug when it exists", ->
|
||||||
|
expect(Discourse.Utilities.categoryUrlId(slug: 'hello')).toBe("hello")
|
||||||
|
|
||||||
|
it "returns id-category when slug is an empty string", ->
|
||||||
|
expect(Discourse.Utilities.categoryUrlId(id: 123, slug: '')).toBe("123-category")
|
||||||
|
|
||||||
|
it "returns id-category without a slug", ->
|
||||||
|
expect(Discourse.Utilities.categoryUrlId(id: 456)).toBe("456-category")
|
||||||
|
|
||||||
describe "Cooking", ->
|
describe "Cooking", ->
|
||||||
|
|
||||||
cook = (contents, opts) ->
|
cook = (contents, opts) ->
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Category do
|
describe Category do
|
||||||
|
@ -59,6 +61,16 @@ describe Category do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'non-english characters' do
|
||||||
|
|
||||||
|
let(:category) { Fabricate(:category, name: "電車男") }
|
||||||
|
|
||||||
|
it "creates a blank slug, this is OK." do
|
||||||
|
category.slug.should be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe 'after create' do
|
describe 'after create' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user