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.2.0"

Class Method Summary collapse

Class Method Details

.assets_dirString

Returns the path to the app/assets/ directory

Returns:

  • (String)


118
119
120
# File 'lib/relay.rb', line 118

def self.assets_dir
  @assets_dir ||= File.join(root, "app", "assets")
end

Returns:

  • (String)


27
28
29
30
31
32
33
34
# File 'lib/relay.rb', line 27

def self.banner
  " ____      _             \n" \
  "|  _ \\ ___| | __ _ _   _ \n" \
  "| |_) / _ \\ |/ _` | | | |\n" \
  "|  _ <  __/ | (_| | |_| |\n" \
  "|_| \\_\\___|_|\\__,_|\\__, |\n" \
  "                   |___/ \n\n"
end

.cacheRelay::InMemoryCache

Returns an object that can be used to store application state that should persist between requests.

Returns:

  • (Relay::InMemoryCache)


68
69
70
# File 'lib/relay.rb', line 68

def self.cache
  @cache
end

.development?Boolean

Returns true when running in development

Returns:

  • (Boolean)


53
54
55
# File 'lib/relay.rb', line 53

def self.development?
  environment == "development"
end

.env_pathString

Returns the path to the Relay env file

Returns:

  • (String)


90
91
92
# File 'lib/relay.rb', line 90

def self.env_path
  @env_path ||= File.join(home, "env")
end

.environmentString

Returns the current Rack environment

Returns:

  • (String)


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

Parameters:

  • path (String)
  • locals (Hash) (defaults to: {})

Returns:

  • (String)


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_dirString

Returns the path to the app/views/fragments directory

Returns:

  • (String)


146
147
148
# File 'lib/relay.rb', line 146

def self.fragments_dir
  @fragments_dir ||= File.join(views_dir, "fragments")
end

.homeString

Returns the writable Relay home directory

Returns:

  • (String)


83
84
85
# File 'lib/relay.rb', line 83

def self.home
  @home ||= ENV["RELAY_HOME"] || File.join(Dir.home, ".relay")
end

.images_dirString

Returns the path to generated images

Returns:

  • (String)


111
112
113
# File 'lib/relay.rb', line 111

def self.images_dir
  @images_dir ||= File.join(home, "g")
end

.logs_dirString

Returns:

  • (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

Parameters:

  • text (String)

    The markdown source

Returns:

  • (String)


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_dirString

Returns the path to the db/migrate directory

Returns:

  • (String)


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

Returns:

  • (Boolean)


60
61
62
# File 'lib/relay.rb', line 60

def self.production?
  environment == "production"
end

.providersLLM::Object

Returns all known providers

Returns:

  • (LLM::Object)


39
40
41
# File 'lib/relay.rb', line 39

def self.providers
  @providers ||= LLM::Object.from(PROVIDERS)
end

.public_dirString

Returns the path to the public/ directory

Returns:

  • (String)


104
105
106
# File 'lib/relay.rb', line 104

def self.public_dir
  @public_dir ||= File.join(root, "public")
end

.reloadArray<String>

Reload Relay (useful in development enviroments)

Parameters:

  • reload (Boolean)

Returns:

  • (Array<String>)


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.message}\n"
          "#{ex.backtrace.join("\n")}"
  end
end

.rendererRedcarpet::Markdown

Returns the shared markdown renderer

Returns:

  • (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_dirString

Returns the path to the app/views/resources directory

Returns:

  • (String)


125
126
127
# File 'lib/relay.rb', line 125

def self.resources_dir
  @resources_dir ||= File.join(root, "app", "resources")
end

.rootString

Returns the root path of the application

Returns:

  • (String)


76
77
78
# File 'lib/relay.rb', line 76

def self.root
  @root ||= File.realpath File.join(__dir__, "..")
end

.tools_dirArray<String>

Returns the tools directory

Returns:

  • (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_dirString

Returns the path to the app/views/ directory

Returns:

  • (String)


132
133
134
# File 'lib/relay.rb', line 132

def self.views_dir
  @views_dir ||= File.join(root, "app", "views")
end