Class: Syntropy::Module
- Inherits:
-
Object
- Object
- Syntropy::Module
- Defined in:
- lib/syntropy/module.rb
Class Attribute Summary collapse
-
.__export_value__ ⇒ Object
readonly
Returns the value of attribute export_value.
Class Method Summary collapse
- .export(ref) ⇒ Object
- .import(ref) ⇒ Object
- .page_list(ref) ⇒ Object
- .prepare(loader:, env:) ⇒ Object
- .route_by_host(map = nil) ⇒ Object
- .template(&block) ⇒ Object
Instance Method Summary collapse
-
#initialize(env) ⇒ Module
constructor
A new instance of Module.
Constructor Details
#initialize(env) ⇒ Module
Returns a new instance of Module.
61 62 63 |
# File 'lib/syntropy/module.rb', line 61 def initialize(env) @env = env end |
Class Attribute Details
.__export_value__ ⇒ Object (readonly)
Returns the value of attribute export_value.
72 73 74 |
# File 'lib/syntropy/module.rb', line 72 def __export_value__ @__export_value__ end |
Class Method Details
.export(ref) ⇒ Object
78 79 80 |
# File 'lib/syntropy/module.rb', line 78 def export(ref) @__export_value__ = ref end |
.import(ref) ⇒ Object
74 75 76 |
# File 'lib/syntropy/module.rb', line 74 def import(ref) @loader.load(ref) end |
.page_list(ref) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/syntropy/module.rb', line 106 def page_list(ref) full_path = File.join(@env[:location], ref) raise 'Not a directory' if !File.directory?(full_path) Dir[File.join(full_path, '*.md')].sort.map { atts, markdown = Syntropy.parse_markdown_file(it, @env) { atts:, markdown: } } end |
.prepare(loader:, env:) ⇒ Object
66 67 68 69 70 |
# File 'lib/syntropy/module.rb', line 66 def prepare(loader:, env:) @loader = loader @env = env const_set(:MODULE, self) end |
.route_by_host(map = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/syntropy/module.rb', line 86 def route_by_host(map = nil) root = @env[:location] sites = Dir[File.join(root, '*')] .select { File.directory?(it) } .each_with_object({}) { |fn, h| name = File.basename(fn) opts = @env.merge(location: fn) h[name] = Syntropy::App.new(opts[:machine], opts[:location], opts[:mount_path], opts) } map&.each do |k, v| sites[k] = sites[v] end lambda { |req| site = sites[req.host] site ? site.call(req) : req.respond(nil, ':status' => Status::BAD_REQUEST) } end |
.template(&block) ⇒ Object
82 83 84 |
# File 'lib/syntropy/module.rb', line 82 def template(&block) Papercraft.html(&block) end |