Module: Syntropy
- Extended by:
- Utilities
- Defined in:
- lib/syntropy.rb,
lib/syntropy/app.rb,
lib/syntropy/test.rb,
lib/syntropy/utils.rb,
lib/syntropy/errors.rb,
lib/syntropy/logger.rb,
lib/syntropy/module.rb,
lib/syntropy/request.rb,
lib/syntropy/version.rb,
lib/syntropy/json_api.rb,
lib/syntropy/markdown.rb,
lib/syntropy/side_run.rb,
lib/syntropy/mime_types.rb,
lib/syntropy/http/client.rb,
lib/syntropy/http/server.rb,
lib/syntropy/http/status.rb,
lib/syntropy/routing_tree.rb,
lib/syntropy/connection_pool.rb,
lib/syntropy/request/response.rb,
lib/syntropy/http/io_extensions.rb,
lib/syntropy/request/validation.rb,
lib/syntropy/request/mock_adapter.rb,
lib/syntropy/request/request_info.rb,
lib/syntropy/http/client_connection.rb,
lib/syntropy/http/server_connection.rb
Defined Under Namespace
Modules: HTTP, MimeTypes, RequestInfoClassMethods, RequestInfoMethods, RequestValidationMethods, ResponseMethods, SideRun, StaticFileCaching, Utilities Classes: App, BadRequestError, ConnectionPool, Error, InvalidRequestContentTypeError, JSONAPI, Logger, MockAdapter, Module, ModuleLoader, ProtocolError, Request, RoutingTree, TestHarness, UnsupportedHTTPVersionError, ValidationError
Constant Summary collapse
- VERSION =
'0.31.0'- DATE_REGEXP =
/(\d{4}-\d{2}-\d{2})/- FRONT_MATTER_REGEXP =
/\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m- YAML_OPTS =
{ permitted_classes: [Date], symbolize_names: true }
Constants included from Utilities
Utilities::BUILTIN_APPLET_ROOT_DIR
Class Attribute Summary collapse
-
.machine ⇒ Object
Returns the value of attribute machine.
Class Method Summary collapse
- .env(env = nil, &app) ⇒ Object
-
.parse_markdown_file(path, env) ⇒ Array
Parses the markdown file at the given path.
- .run(env = {}, &app) ⇒ Object
- .side_run(&block) ⇒ Object
Methods included from Utilities
app, builtin_applet, page_list, route_by_host
Class Attribute Details
.machine ⇒ Object
Returns the value of attribute machine.
26 27 28 |
# File 'lib/syntropy.rb', line 26 def machine @machine end |
Class Method Details
.env(env = nil, &app) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/syntropy.rb', line 59 def env(env = nil, &app) return @env if !env && !app @env = env || {} @env[:app] = app if app end |
.parse_markdown_file(path, env) ⇒ Array
Parses the markdown file at the given path.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/syntropy/markdown.rb', line 17 def self.parse_markdown_file(path, env) content = IO.read(path) || '' atts = {} # Parse date from file name m = path.match(DATE_REGEXP) atts[:date] ||= Date.parse(m[1]) if m if (m = content.match(FRONT_MATTER_REGEXP)) front_matter = m[1] content = m.post_match yaml = YAML.safe_load(front_matter, **YAML_OPTS) atts = atts.merge(yaml) end if env[:root_dir] atts[:url] = path .gsub(/#{env[:root_dir]}/, '') .gsub(/\.md$/, '') end [atts, content] end |
.run(env = {}, &app) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/syntropy.rb', line 36 def run(env = {}, &app) if @in_run @env = env @env[:app] = app if app return end env ||= @env || {} begin @in_run = true machine = env[:machine] || UM.new env[:logger]&.info(message: "Running Syntropy #{Syntropy::VERSION}, UringMachine #{UM::VERSION}, Ruby #{RUBY_VERSION}") server = HTTP::Server.new(machine, env, &app) setup_signal_handling(machine, Fiber.current) server.run ensure @in_run = false end end |