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
- .app(location = nil, mount_path = nil) ⇒ Object
- .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.
62 63 64 |
# File 'lib/syntropy/module.rb', line 62 def initialize(env) @env = env end |
Class Attribute Details
.__export_value__ ⇒ Object (readonly)
Returns the value of attribute export_value.
74 75 76 |
# File 'lib/syntropy/module.rb', line 74 def __export_value__ @__export_value__ end |
Class Method Details
.app(location = nil, mount_path = nil) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/syntropy/module.rb', line 119 def app(location = nil, mount_path = nil) location ||= @env[:location] mount_path ||= @env[:mount_path] opts = @env.merge(location:, mount_path:) Syntropy::App.new(opts[:machine], opts[:location], opts[:mount_path], opts) end |
.export(ref) ⇒ Object
80 81 82 |
# File 'lib/syntropy/module.rb', line 80 def export(ref) @__export_value__ = ref end |
.import(ref) ⇒ Object
76 77 78 |
# File 'lib/syntropy/module.rb', line 76 def import(ref) @loader.load(ref) end |
.page_list(ref) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/syntropy/module.rb', line 109 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
67 68 69 70 71 72 |
# File 'lib/syntropy/module.rb', line 67 def prepare(loader:, env:) @loader = loader @env = env @machine = env[:machine] const_set(:MODULE, self) end |
.route_by_host(map = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/syntropy/module.rb', line 88 def route_by_host(map = nil) root = @env[:location] sites = Dir[File.join(root, '*')] .reject { File.basename(it) =~ /^_/ } .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
84 85 86 |
# File 'lib/syntropy/module.rb', line 84 def template(&block) Papercraft.html(&block) end |