Module: Relay
- Defined in:
- app/init.rb,
lib/relay.rb,
lib/relay/test.rb,
lib/relay/tool.rb,
app/init/router.rb,
lib/relay/model.rb,
lib/relay/theme.rb,
lib/relay/jukebox.rb,
lib/relay/version.rb,
lib/relay/markdown.rb,
lib/relay/reloader.rb
Defined Under Namespace
Modules: Cache, Concerns, Database, Forms, Hooks, Model, Models, Pages, Routes, Tool, Tools, Validators Classes: Attachment, Jukebox, Markdown, Reloader, Router, Task, TaskMonitor, Test
Constant Summary collapse
- THEME =
"dark"- DB =
Relay::Database.connect!(env: Relay.environment)
- VERSION =
"0.6.0"
Class Method Summary collapse
-
.assets_dir ⇒ String
Returns the path to the app/assets/ directory.
- .banner ⇒ String
-
.bootstrap! ⇒ String
Creates the Relay home layout and copies bundled defaults into it.
-
.cache ⇒ Relay::InMemoryCache
Returns an object that can be used to store application state that should persist between requests.
-
.development? ⇒ Boolean
Returns true when running in development.
-
.env_path ⇒ String
Returns the path to the Relay env file.
-
.environment ⇒ String
Returns the current Rack environment.
-
.erb(path, locals = {}) ⇒ String
Renders an erb template.
-
.fragments_dir ⇒ String
Returns the path to the app/views/fragments directory.
-
.home ⇒ String
Returns the writable Relay home directory.
-
.images_dir ⇒ String
Returns the path to generated images.
-
.loader ⇒ Zeitwerk::Loader
Returns the Zeitwerk loader used for application autoloading.
- .logs_dir ⇒ String
-
.markdown(text) ⇒ String
Renders markdown to HTML.
-
.migrations_dir ⇒ String
Returns the path to the db/migrate directory.
-
.production? ⇒ Boolean
Returns true when running in production.
-
.providers ⇒ LLM::Object
Returns all known providers.
-
.public_dir ⇒ String
Returns the path to the public/ directory.
-
.reload ⇒ Array<String>
Reload Relay (useful in development enviroments).
-
.renderer ⇒ Redcarpet::Markdown
Returns the shared markdown renderer.
-
.resources_dir ⇒ String
Returns the path to the app/views/resources directory.
-
.root ⇒ String
Returns the root path of the application.
-
.tools_dir ⇒ Array<String>
Returns the tools directory.
-
.user_loader ⇒ Zeitwerk::Loader
Returns the Zeitwerk loader used for user-installed tools.
-
.views_dir ⇒ String
Returns the path to the app/views/ directory.
Class Method Details
.assets_dir ⇒ String
Returns the path to the app/assets/ directory
137 138 139 |
# File 'lib/relay.rb', line 137 def self.assets_dir @assets_dir ||= File.join(root, "app", "assets") end |
.banner ⇒ String
31 32 33 34 35 36 37 38 |
# File 'lib/relay.rb', line 31 def self. " ____ _ \n" \ "| _ \\ ___| | __ _ _ _ \n" \ "| |_) / _ \\ |/ _` | | | |\n" \ "| _ < __/ | (_| | |_| |\n" \ "|_| \\_\\___|_|\\__,_|\\__, |\n" \ " |___/ \n\n" end |
.bootstrap! ⇒ String
Creates the Relay home layout and copies bundled defaults into it.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/relay.rb', line 101 def self.bootstrap! FileUtils.mkdir_p home FileUtils.mkdir_p File.join(home, "db") FileUtils.mkdir_p File.join(home, "tools") FileUtils.mkdir_p images_dir FileUtils.mkdir_p logs_dir source = File.join(root, "db", "config.yml") destination = File.join(home, "db", "config.yml") FileUtils.cp(source, destination) if File.exist?(source) && !File.exist?(destination) home end |
.cache ⇒ Relay::InMemoryCache
Returns an object that can be used to store application state that should persist between requests.
72 73 74 |
# File 'lib/relay.rb', line 72 def self.cache @cache end |
.development? ⇒ Boolean
Returns true when running in development
57 58 59 |
# File 'lib/relay.rb', line 57 def self.development? environment == "development" end |
.env_path ⇒ String
Returns the path to the Relay env file
94 95 96 |
# File 'lib/relay.rb', line 94 def self.env_path @env_path ||= File.join(home, "env") end |
.environment ⇒ String
Returns the current Rack environment
50 51 52 |
# File 'lib/relay.rb', line 50 def self.environment ENV["RACK_ENV"] || "development" end |
.erb(path, locals = {}) ⇒ String
Renders an erb template
180 181 182 183 |
# File 'lib/relay.rb', line 180 def self.erb(path, locals = {}) tmpl = File.read File.join(views_dir, path) ERB.new(tmpl).result_with_hash(locals) end |
.fragments_dir ⇒ String
Returns the path to the app/views/fragments directory
165 166 167 |
# File 'lib/relay.rb', line 165 def self.fragments_dir @fragments_dir ||= File.join(views_dir, "fragments") end |
.home ⇒ String
Returns the writable Relay home directory
87 88 89 |
# File 'lib/relay.rb', line 87 def self.home @home ||= ENV["RELAY_HOME"] || File.join(Dir.home, ".config", "relay") end |
.images_dir ⇒ String
Returns the path to generated images
130 131 132 |
# File 'lib/relay.rb', line 130 def self.images_dir @images_dir ||= File.join(public_dir, "g") end |
.loader ⇒ Zeitwerk::Loader
Returns the Zeitwerk loader used for application autoloading
35 36 37 |
# File 'app/init.rb', line 35 def self.loader @loader end |
.logs_dir ⇒ String
171 172 173 |
# File 'lib/relay.rb', line 171 def self.logs_dir @logs_dir ||= File.join(home, "tmp") end |
.markdown(text) ⇒ String
Renders markdown to HTML
11 12 13 |
# File 'lib/relay/markdown.rb', line 11 def self.markdown(text) renderer.render(text.to_s.gsub(/\r\n?/, "\n")) end |
.migrations_dir ⇒ String
Returns the path to the db/migrate directory
158 159 160 |
# File 'lib/relay.rb', line 158 def self.migrations_dir @migrations_dir ||= File.join(root, "db", "migrate") end |
.production? ⇒ Boolean
Returns true when running in production
64 65 66 |
# File 'lib/relay.rb', line 64 def self.production? environment == "production" end |
.providers ⇒ LLM::Object
Returns all known providers
43 44 45 |
# File 'lib/relay.rb', line 43 def self.providers @providers ||= LLM::Object.from(PROVIDERS).transform_values!(&:call) end |
.public_dir ⇒ String
Returns the path to the public/ directory
123 124 125 |
# File 'lib/relay.rb', line 123 def self.public_dir @public_dir ||= File.join(root, "public") end |
.reload ⇒ Array<String>
Reload Relay (useful in development enviroments)
189 190 191 192 193 194 195 |
# File 'lib/relay.rb', line 189 def self.reload LLM::Tool.clear_registry! Relay.loader.reload if development? Relay.user_loader.reload if development? Relay.user_loader.eager_load Relay.loader.eager_load_dir(tools_dir) end |
.renderer ⇒ Redcarpet::Markdown
Returns the shared markdown renderer
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/relay/markdown.rb', line 18 def self.renderer Redcarpet::Markdown.new( Markdown.new(filter_html: false, safe_links_only: true), autolink: true, fenced_code_blocks: true, lax_spacing: true, no_intra_emphasis: true, tables: true ) end |
.resources_dir ⇒ String
Returns the path to the app/views/resources directory
144 145 146 |
# File 'lib/relay.rb', line 144 def self.resources_dir @resources_dir ||= File.join(root, "app", "resources") end |
.root ⇒ String
Returns the root path of the application
80 81 82 |
# File 'lib/relay.rb', line 80 def self.root @root ||= File.realpath File.join(__dir__, "..") end |
.tools_dir ⇒ Array<String>
Returns the tools directory
116 117 118 |
# File 'lib/relay.rb', line 116 def self.tools_dir @tools_dir ||= File.join(root, "app", "tools") end |
.user_loader ⇒ Zeitwerk::Loader
Returns the Zeitwerk loader used for user-installed tools
51 52 53 |
# File 'app/init.rb', line 51 def self.user_loader @user_loader end |
.views_dir ⇒ String
Returns the path to the app/views/ directory
151 152 153 |
# File 'lib/relay.rb', line 151 def self.views_dir @views_dir ||= File.join(root, "app", "views") end |