mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 15:53:45 +08:00
a3e8c3cd7b
This feature introduces the concept of themes. Themes are an evolution of site customizations. Themes introduce two very big conceptual changes: - A theme may include other "child themes", children can include grand children and so on. - A theme may specify a color scheme The change does away with the idea of "enabled" color schemes. It also adds a bunch of big niceties like - You can source a theme from a git repo - History for themes is much improved - You can only have a single enabled theme. Themes can be selected by users, if you opt for it. On a technical level this change comes with a whole bunch of goodies - All CSS is now compiled using a custom pipeline that uses libsass see /lib/stylesheet - There is a single pipeline for css compilation (in the past we used one for customizations and another one for the rest of the app - The stylesheet pipeline is now divorced of sprockets, there is no reliance on sprockets for CSS bundling - CSS is generated with source maps everywhere (including themes) this makes debugging much easier - Our "live reloader" is smarter and avoid a flash of unstyled content we run a file watcher in "puma" in dev so you no longer need to run rake autospec to watch for CSS changes
70 lines
2.0 KiB
Ruby
70 lines
2.0 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'site'
|
|
|
|
describe Site do
|
|
|
|
def expect_correct_themes(guardian)
|
|
json = Site.json_for(guardian)
|
|
parsed = JSON.parse(json)
|
|
|
|
expected = Theme.where('key = :default OR user_selectable',
|
|
default: SiteSetting.default_theme_key)
|
|
.order(:name)
|
|
.pluck(:key, :name)
|
|
.map{|k,n| {"theme_key" => k, "name" => n, "default" => k == SiteSetting.default_theme_key}}
|
|
|
|
expect(parsed["user_themes"]).to eq(expected)
|
|
end
|
|
|
|
it "includes user themes and expires them as needed" do
|
|
default_theme = Theme.create!(user_id: -1, name: 'default')
|
|
SiteSetting.default_theme_key = default_theme.key
|
|
user_theme = Theme.create!(user_id: -1, name: 'user theme', user_selectable: true)
|
|
|
|
anon_guardian = Guardian.new
|
|
user_guardian = Guardian.new(Fabricate(:user))
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
expect_correct_themes(user_guardian)
|
|
|
|
Theme.clear_default!
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
expect_correct_themes(user_guardian)
|
|
|
|
user_theme.user_selectable = false
|
|
user_theme.save!
|
|
|
|
expect_correct_themes(anon_guardian)
|
|
expect_correct_themes(user_guardian)
|
|
|
|
end
|
|
|
|
it "omits categories users can not write to from the category list" do
|
|
category = Fabricate(:category)
|
|
user = Fabricate(:user)
|
|
|
|
expect(Site.new(Guardian.new(user)).categories.count).to eq(2)
|
|
|
|
category.set_permissions(:everyone => :create_post)
|
|
category.save
|
|
|
|
guardian = Guardian.new(user)
|
|
|
|
expect(Site.new(guardian)
|
|
.categories
|
|
.keep_if{|c| c.name == category.name}
|
|
.first
|
|
.permission)
|
|
.not_to eq(CategoryGroup.permission_types[:full])
|
|
|
|
# If a parent category is not visible, the child categories should not be returned
|
|
category.set_permissions(:staff => :full)
|
|
category.save
|
|
|
|
sub_category = Fabricate(:category, parent_category_id: category.id)
|
|
expect(Site.new(guardian).categories).not_to include(sub_category)
|
|
end
|
|
|
|
end
|