require "ecr/macros" require "../page" class Guff::TestAuthHTMLView TITLE = "Guff Auth Test" FEATURES = %w{bootstrap font-awesome guff/util} SCRIPTS = %w{ /guff-stuff/ckeditor-4.5.8-custom/ckeditor.js /guff-stuff/js/search-field.js /guff-stuff/test/tab-users.js /guff-stuff/test/tab-posts.js } TEMPLATES = TemplateCache.new({ role: " ", tab: " ", new_post_button: " New Post ", }) def self.run(models, context : HTTP::Server::Context) new(models).run(context) end def initialize(@models : Models) end def run(context) page = PageHTMLView.new(TITLE, self.to_s) page.add_features(FEATURES) page.scripts.concat(SCRIPTS) context.response.content_type = page.content_type context.response.puts page end def h(s : String) HTML.escape(s || "") end def get_roles @models.role.get_roles.map { |row| name = row["role_name"] as String TEMPLATES[:role].run({ "name": h(name), "text": h(row["role_desc"] as String), "selected": (name == "guest") ? "selected='selected'" : "" }) }.join end def get_tabs(id : Symbol, prefix : String) @models.tab.get_tabs(id).map { |row| TEMPLATES[:tab].run(row.merge({ "prefix": prefix, "css": row["css"]? || "", "name": h(row["name"]), "text": h(row["text"]), })) }.join end def get_new_post_button TEMPLATES[:new_post_button].run end ECR.def_to_s("./src/guff/views/ecrs/test/auth.ecr") end