Class: MarkdownServer::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/markdown_server/app.rb

Constant Summary collapse

EXCLUDED =
MarkdownServer::EXCLUDED
EDITOR_FILE_MAX_BYTES =
5 * 1024 * 1024
EDITOR_PKGS =
{
  "@codemirror/state"           => "6.6.0",
  "@codemirror/view"            => "6.41.1",
  "@codemirror/commands"        => "6.10.3",
  "@codemirror/language"        => "6.12.3",
  "@codemirror/search"          => "6.7.0",
  "@codemirror/autocomplete"    => "6.20.1",
  "@codemirror/theme-one-dark"  => "6.1.3",
  "@codemirror/lang-markdown"   => "6.5.0",
  "@codemirror/lang-javascript" => "6.2.5",
  "@codemirror/lang-json"       => "6.0.2",
  "@codemirror/lang-yaml"       => "6.1.3",
  "@codemirror/lang-html"       => "6.4.11",
  "@codemirror/lang-css"        => "6.3.1",
  "@codemirror/lang-python"     => "6.2.1",
  "@codemirror/legacy-modes"    => "6.5.2",
  "@replit/codemirror-vim"      => "6.3.0"
}.freeze
EDITOR_SHARED_DEPS =
%w[
  @codemirror/state
  @codemirror/view
  @codemirror/language
  @codemirror/commands
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_plugins!Object



68
69
70
71
72
73
74
75
# File 'lib/markdown_server/app.rb', line 68

def self.load_plugins!
  Dir[File.join(__dir__, "plugins", "*", "plugin.rb")].sort.each { |f| require f }
  set :plugins, PluginRegistry.load_plugins(
    settings.root_dir,
    settings.plugin_overrides,
    plugin_dirs: settings.plugin_dirs
  )
end

Instance Method Details

#editor_import_map_jsonObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/markdown_server/app.rb', line 166

def editor_import_map_json
  @@editor_import_map_json ||= begin
    imports = {}
    EDITOR_PKGS.each do |pkg, ver|
      deps = EDITOR_SHARED_DEPS.reject { |d| d == pkg }
      imports[pkg] = "https://esm.sh/#{pkg}@#{ver}?external=#{deps.join(",")}"
    end
    EDITOR_PKGS.each do |pkg, ver|
      next unless pkg == "@codemirror/legacy-modes"
      %w[ruby shell].each do |mode|
        deps = EDITOR_SHARED_DEPS.reject { |d| d == pkg }
        imports["#{pkg}/mode/#{mode}"] =
          "https://esm.sh/#{pkg}@#{ver}/mode/#{mode}.js?external=#{deps.join(",")}"
      end
    end
    JSON.dump({ imports: imports })
  end
end

#editor_loader_pathObject



130
131
132
# File 'lib/markdown_server/app.rb', line 130

def editor_loader_path
  @@editor_loader_path ||= File.expand_path("assets/editor-loader.js", __dir__)
end

#editor_loader_versionObject



134
135
136
137
138
# File 'lib/markdown_server/app.rb', line 134

def editor_loader_version
  path = editor_loader_path
  content = File.read(path) + editor_import_map_json
  Digest::SHA256.hexdigest(content)[0, 10]
end