aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guff/models/theme.cr25
-rw-r--r--src/guff/views/page.cr12
2 files changed, 24 insertions, 13 deletions
diff --git a/src/guff/models/theme.cr b/src/guff/models/theme.cr
index 275ddff..76d9ea6 100644
--- a/src/guff/models/theme.cr
+++ b/src/guff/models/theme.cr
@@ -183,12 +183,12 @@ class Guff::Models::ThemeModel < Guff::Models::Model
row = get(theme_id: theme_id)
# load templates
- @cache[:templates][theme_id] = Template::Cache.new(if row["is_system"] == "1"
+ @cache[:templates][theme_id] = Template::Cache.new(if is_system?(row)
# read templates from templates dir
read_templates(File.join(
- @context.system_dir,
+ @context.config.system_dir,
"themes",
- row["theme_slug"],
+ row["theme_slug"].to_s,
"templates"
))
else
@@ -206,7 +206,7 @@ class Guff::Models::ThemeModel < Guff::Models::Model
row = get(theme_id: theme_id)
# load templates
- @cache[:metadata][theme_id] = (if row["is_system"] == "1"
+ @cache[:metadata][theme_id] = (if is_system?(row)
# system themes have no metadata (for now)
{} of String => String
else
@@ -219,16 +219,19 @@ class Guff::Models::ThemeModel < Guff::Models::Model
end
private def read_templates(dir_path : String) : Hash(String, String)
- Dir.glob(File.join(templates_dir, "**/*")).reduce(
+ Dir.glob(File.join(dir_path, "*")).select { |path|
+ # skip hidden files
+ File.basename(path) =~ /\A[^\.]/m
+ }.reduce(
{} of String => String
) do |r, path|
- r[path.gsub(templates_dir + "/", "")] = File.read(path)
+ r[path.gsub(dir_path + "/", "")] = File.read(path, "utf8")
r
end
end
private def get_data(theme_id : Int32, type : String)
- r = {} of String => Hash(String, String)
+ r = {} of String => String
@context.dbs.ro.all(SQL[:get_data], [theme_id.to_s, type]) do |row|
r[row["data_key"].to_s] = row["data_val"].to_s
@@ -238,6 +241,10 @@ class Guff::Models::ThemeModel < Guff::Models::Model
r
end
+ private def is_system?(row) : Bool
+ (row["is_system"] as Int64) == 1
+ end
+
###############
# add methods #
###############
@@ -310,7 +317,7 @@ class Guff::Models::ThemeModel < Guff::Models::Model
theme = get(slug: slug)
return nil unless theme
- if theme["is_system"].to_s == "1"
+ if is_system?(theme)
File.join(
@context.config.system_dir,
"themes",
@@ -362,7 +369,7 @@ class Guff::Models::ThemeModel < Guff::Models::Model
# get theme
theme = get(theme_id: theme_id)
- @cache[:assets][theme_id] = (if theme["is_system"].to_s == "1"
+ @cache[:assets][theme_id] = (if is_system?(theme)
# load manifest for system theme
Theme::Packer::Manifest.load(File.join(
@context.config.system_dir,
diff --git a/src/guff/views/page.cr b/src/guff/views/page.cr
index 95f91bd..dc628b3 100644
--- a/src/guff/views/page.cr
+++ b/src/guff/views/page.cr
@@ -7,11 +7,10 @@ class Guff::Views::PageView < Guff::Views::HTMLView
@item[k]? && @item[k].size > 0
}].not_nil!.to_i32 as Int32
- # get theme slug
+ # get theme slug, assets, and templates
@theme_slug = @context.models.theme.get(@theme_id)["theme_slug"] as String
-
- # get theme assets
@theme_assets = @context.models.theme.assets(@theme_id) as Theme::Assets
+ @theme_templates = @context.models.theme.templates(@theme_id) as Template::Cache
# get page assets
@page_assets = @context.models.page.assets(@item["post_id"].to_i64) as Theme::Assets
@@ -35,5 +34,10 @@ class Guff::Views::PageView < Guff::Views::HTMLView
THEME_ASSET_PATH % [@theme_slug, asset_path]
end
- ECR.def_to_s("src/views/page.ecr")
+ def to_s(io)
+ @theme_templates["page.html"].run(io, @item.merge({
+ "scripts" => scripts,
+ "styles" => styles,
+ }))
+ end
end