Module: Relay
- Defined in:
- 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.1.0.beta.1"
Class Method Summary collapse
-
.assets_dir ⇒ String
Returns the path to the app/assets/ directory.
- .banner ⇒ String
-
.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.
- .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.
-
.theme_path ⇒ String
Returns the absolute path to the theme stylesheet.
-
.themes_dir ⇒ String
Returns the directory that stores theme stylesheets.
-
.tools_dir ⇒ Array<String>
Returns the tools directory.
-
.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
118 119 120 |
# File 'lib/relay.rb', line 118 def self.assets_dir @assets_dir ||= File.join(root, "app", "assets") end |
.banner ⇒ String
27 28 29 30 31 32 33 34 |
# File 'lib/relay.rb', line 27 def self. " ____ _ \n" \ "| _ \\ ___| | __ _ _ _ \n" \ "| |_) / _ \\ |/ _` | | | |\n" \ "| _ < __/ | (_| | |_| |\n" \ "|_| \\_\\___|_|\\__,_|\\__, |\n" \ " |___/ \n\n" end |
.cache ⇒ Relay::InMemoryCache
Returns an object that can be used to store application state that should persist between requests.
68 69 70 |
# File 'lib/relay.rb', line 68 def self.cache @cache end |
.development? ⇒ Boolean
Returns true when running in development
53 54 55 |
# File 'lib/relay.rb', line 53 def self.development? environment == "development" end |
.env_path ⇒ String
Returns the path to the Relay env file
90 91 92 |
# File 'lib/relay.rb', line 90 def self.env_path @env_path ||= File.join(home, "env") end |
.environment ⇒ String
Returns the current Rack environment
46 47 48 |
# File 'lib/relay.rb', line 46 def self.environment ENV["RACK_ENV"] || "development" end |
.erb(path, locals = {}) ⇒ String
Renders an erb template
161 162 163 164 |
# File 'lib/relay.rb', line 161 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
146 147 148 |
# File 'lib/relay.rb', line 146 def self.fragments_dir @fragments_dir ||= File.join(views_dir, "fragments") end |
.home ⇒ String
Returns the writable Relay home directory
83 84 85 |
# File 'lib/relay.rb', line 83 def self.home @home ||= ENV["RELAY_HOME"] || File.join(Dir.home, ".relay") end |
.images_dir ⇒ String
Returns the path to generated images
111 112 113 |
# File 'lib/relay.rb', line 111 def self.images_dir @images_dir ||= File.join(home, "g") end |
.logs_dir ⇒ String
152 153 154 |
# File 'lib/relay.rb', line 152 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
139 140 141 |
# File 'lib/relay.rb', line 139 def self.migrations_dir @migrations_dir ||= File.join(root, "db", "migrate") end |
.production? ⇒ Boolean
Returns true when running in production
60 61 62 |
# File 'lib/relay.rb', line 60 def self.production? environment == "production" end |
.providers ⇒ LLM::Object
Returns all known providers
39 40 41 |
# File 'lib/relay.rb', line 39 def self.providers @providers ||= LLM::Object.from(PROVIDERS) end |
.public_dir ⇒ String
Returns the path to the public/ directory
104 105 106 |
# File 'lib/relay.rb', line 104 def self.public_dir @public_dir ||= File.join(root, "public") end |
.reload ⇒ Array<String>
Reload Relay (useful in development enviroments)
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/relay.rb', line 170 def self.reload LLM::Tool.clear_registry! Relay.loader.reload paths = Dir[File.join(tools_dir, "*.rb")] paths.concat Dir[File.join(home, "tools", "*.rb")] paths.sort.each do load(_1) rescue => ex warn "tool error\n" "#{ex.class}: #{ex.}\n" "#{ex.backtrace.join("\n")}" end 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
125 126 127 |
# File 'lib/relay.rb', line 125 def self.resources_dir @resources_dir ||= File.join(root, "app", "resources") end |
.root ⇒ String
Returns the root path of the application
76 77 78 |
# File 'lib/relay.rb', line 76 def self.root @root ||= File.realpath File.join(__dir__, "..") end |
.theme_path ⇒ String
Returns the absolute path to the theme stylesheet.
16 17 18 |
# File 'lib/relay/theme.rb', line 16 def self.theme_path File.join(themes_dir, "#{THEME}.css") end |
.themes_dir ⇒ String
Returns the directory that stores theme stylesheets.
9 10 11 |
# File 'lib/relay/theme.rb', line 9 def self.themes_dir @themes_dir ||= File.join(assets_dir, "css", "themes") end |
.tools_dir ⇒ Array<String>
Returns the tools directory
97 98 99 |
# File 'lib/relay.rb', line 97 def self.tools_dir @tools_dir ||= File.join(root, "app", "tools") end |
.views_dir ⇒ String
Returns the path to the app/views/ directory
132 133 134 |
# File 'lib/relay.rb', line 132 def self.views_dir @views_dir ||= File.join(root, "app", "views") end |