((.|\n)*)<\/code>/) {
+ html = HTML.unescape($1)
+
+ tokenized = SemanticTokenizer.highlight(html, "example.mint", true)
+
+ "#{tokenized}
"
+ }
+ end
+
+ def source(node : Ast::Node) : String
+ @formatter.source(node)
+ end
+
+ def source(node : Ast::Node | Nil) : String
+ ""
+ end
+
+ def search(node)
+ "#{stringify(node)}|#{stringify(children(node))}".downcase
+ end
+
+ def children(category : String, subcategory : String, page : Ast::Node, children : Array(Ast::Node)) : Array(Page)
+ children
+ .sort_by(&.name.value)
+ .map { |node| Page.new(category, subcategory, page.name.value, node.name.value) }
+ end
+
+ def children(node)
+ [] of Page
+ end
+
+ def is_page_active(category : String, node : Ast::Node)
+ category == @category && stringify(node) == @page
+ end
+
+ def is_git_repo
+ `git rev-parse --is-inside-work-tree`.strip == "true"
+ end
+
+ def parse_git_root : String
+ if is_git_repo
+ `git rev-parse --show-toplevel`.strip
+ else
+ ""
+ end
+ end
+
+ def base_url
+ if @base == ""
+ "/"
+ else
+ ""
+ end
+ end
+
+ def readme_url
+ "#{base_url}index.html"
+ end
+
+ def page_url(category : String, page : String)
+ "#{base_url}#{category}/#{page}.html"
+ end
+
+ def anchor_url(node)
+ "#{page_url(@category, @page)}##{stringify(node)}"
+ end
+
+ def anchor_url(child : Page)
+ "#{page_url(child.category, child.parent)}##{child.name}"
+ end
+
+ def type_url(type : String)
+ core = @core_types.fetch(type, "")
+ own = @types.fetch(type, "")
+
+ if own != ""
+ page_url(own, type)
+ elsif core != ""
+ "https://mint-lang.com/api/#{core}/#{type}"
+ else
+ ""
+ end
+ end
+
+ def source_url(node)
+ url = @mint_json.source_url
+ user, repo = SourceUrl.parse_user_and_repo(url)
+ path = node.location.filename.sub("#{@git_root}/", "")
+ line = node.location.start[0]
+ s_url =
+ if url.includes?("github")
+ "https://github.com/#{user}/#{repo}/blob/#{@git_ref}/#{path}#L#{line}"
+ elsif url.includes?("gitlab")
+ "https://gitlab.com/#{user}/#{repo}/blob/#{@git_ref}/#{path}#L#{line}"
+ elsif url.includes?("bitbucket")
+ "https://bitbucket.org/#{user}/#{repo}/src/#{@git_ref}/#{path}#cl-#{line}"
+ else
+ ""
+ end
+
+ if s_url.empty?
+ ""
+ else
+ ""
+ end
+ end
+ end
end
diff --git a/src/documentation_generator/argument.cr b/src/documentation_generator/argument.cr
index 3a9f627b3..428e84344 100644
--- a/src/documentation_generator/argument.cr
+++ b/src/documentation_generator/argument.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Argument, json : JSON::Builder)
json.object do
json.field "type", stringify(node.type)
@@ -7,4 +7,14 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Argument)
+ render("#{__DIR__}/html/argument.ecr")
+ end
+
+ def stringify(node : Ast::Argument)
+ node.name.value
+ end
+ end
end
diff --git a/src/documentation_generator/component.cr b/src/documentation_generator/component.cr
index a083721a6..cf0a5d44b 100644
--- a/src/documentation_generator/component.cr
+++ b/src/documentation_generator/component.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Component, json : JSON::Builder)
json.object do
json.field "description", node.comment.try(&.to_html)
@@ -33,4 +33,24 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Component)
+ render("#{__DIR__}/html/component.ecr")
+ end
+
+ def stringify(node : Ast::Component)
+ node.name.value
+ end
+
+ def children(node : Ast::Component)
+ children("components", "property", node, node.properties) |
+ children("components", "state", node, node.states) |
+ children("components", "function", node, node.functions)
+ end
+
+ def comment(node : Ast::Node)
+ render("#{__DIR__}/html/comment.ecr")
+ end
+ end
end
diff --git a/src/documentation_generator/connect.cr b/src/documentation_generator/connect.cr
index e949bbc57..968ce73d9 100644
--- a/src/documentation_generator/connect.cr
+++ b/src/documentation_generator/connect.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Connect, json : JSON::Builder)
json.object do
json.field "keys", node.keys.map(&.name.value)
diff --git a/src/documentation_generator/function.cr b/src/documentation_generator/function.cr
index 96228e752..45ee06184 100644
--- a/src/documentation_generator/function.cr
+++ b/src/documentation_generator/function.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Function, json : JSON::Builder)
json.object do
json.field "type", node.type.try { |item| stringify(item) }
@@ -13,4 +13,18 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Function)
+ render("#{__DIR__}/html/function.ecr")
+ end
+
+ def stringify(node : Ast::Function)
+ node.name.value
+ end
+
+ def comment(node : Ast::Function)
+ render("#{__DIR__}/html/comment.ecr")
+ end
+ end
end
diff --git a/src/documentation_generator/get.cr b/src/documentation_generator/get.cr
index 6ee132e12..44abc9ed7 100644
--- a/src/documentation_generator/get.cr
+++ b/src/documentation_generator/get.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Get, json : JSON::Builder)
json.object do
json.field "type", node.type.try { |item| stringify(item) }
diff --git a/src/documentation_generator/html/argument.ecr b/src/documentation_generator/html/argument.ecr
new file mode 100644
index 000000000..eb3283de5
--- /dev/null
+++ b/src/documentation_generator/html/argument.ecr
@@ -0,0 +1,7 @@
+
+
+ <%= stringify(node) %>
+
+
+ <%= generate(node.type) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/comment.ecr b/src/documentation_generator/html/comment.ecr
new file mode 100644
index 000000000..2d183db87
--- /dev/null
+++ b/src/documentation_generator/html/comment.ecr
@@ -0,0 +1,5 @@
+<% if node.comment != nil %>
+
+ <%= node.comment.try(&.to_html) %>
+
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/component.ecr b/src/documentation_generator/html/component.ecr
new file mode 100644
index 000000000..7c5a421e0
--- /dev/null
+++ b/src/documentation_generator/html/component.ecr
@@ -0,0 +1,37 @@
+
+ <%= stringify(node) %>
+
+ <%= source_url(node) %>
+
+
+<%= comment(node) %>
+
+<% if node.properties.size > 0 %>
+
+ Properties
+
+
+ <% node.properties.sort_by(&.name.value).each do |p| %>
+ <%= generate(p) %>
+ <% end %>
+<% end %>
+
+<% if node.states.size > 0 %>
+
+ States
+
+
+ <% node.states.sort_by(&.name.value).each do |s| %>
+ <%= generate(s) %>
+ <% end %>
+<% end %>
+
+<% if node.functions.size > 0 %>
+
+ Functions
+
+
+ <% node.functions.sort_by(&.name.value).each do |f| %>
+ <%= generate(f) %>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/default.ecr b/src/documentation_generator/html/default.ecr
new file mode 100644
index 000000000..49cb41582
--- /dev/null
+++ b/src/documentation_generator/html/default.ecr
@@ -0,0 +1,13 @@
+<% default = source(node.default) %>
+
+<% if default != "" %>
+ <% block = default.size > 50 ? "entity__default--block" : "" %>
+
+
+ =
+
+
+
+ <%= default %>
+
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/function.ecr b/src/documentation_generator/html/function.ecr
new file mode 100644
index 000000000..7c5cab08b
--- /dev/null
+++ b/src/documentation_generator/html/function.ecr
@@ -0,0 +1,26 @@
+
+
+
+
+
+ <%= stringify(node) %>
+
+
+ <% if node.arguments.try(&.to_a.any?) %>
+ (
+
+ <% node.arguments.each do |a| %>
+ <%= generate(a) %>
+ <% end %>
+
+ )
+ <% end %>
+
+ <%= generate(node.type) %>
+
+ <%= source_url(node) %>
+
+
+
+ <%= comment(node) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/module.ecr b/src/documentation_generator/html/module.ecr
new file mode 100644
index 000000000..1a4e0123a
--- /dev/null
+++ b/src/documentation_generator/html/module.ecr
@@ -0,0 +1,13 @@
+
+ <%= stringify(node) %>
+
+ <%= source_url(node) %>
+
+
+<%= comment(node) %>
+
+Functions
+
+<% node.functions.sort_by(&.name.value).each do |f| %>
+ <%= generate(f) %>
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/nav_item.ecr b/src/documentation_generator/html/nav_item.ecr
new file mode 100644
index 000000000..4b0aa6009
--- /dev/null
+++ b/src/documentation_generator/html/nav_item.ecr
@@ -0,0 +1,30 @@
+
+
+
+
+
+<% children(node).each do |child| %>
+
+ <% if !is_page_active(category, node) %>
+ style="display: none"
+ <% end %>
+>
+
+
+
+
+<% end %>
diff --git a/src/documentation_generator/html/page.ecr b/src/documentation_generator/html/page.ecr
new file mode 100644
index 000000000..9d5361e06
--- /dev/null
+++ b/src/documentation_generator/html/page.ecr
@@ -0,0 +1,160 @@
+
+
+
+ <% if @base != "" %>
+
+ <% end %>
+
+ <%= @mint_json.name %> | <%= @page %>
+
+
+
+
+
+
+
+
+
+
+ Pages
+
+
+
+
+
+ <%= @mint_json.name %>
+
+
+ Basic information
+
+
+
+
+
+ README
+
+
+
+ <% if !@mint_json.source_url.empty? %>
+
+
+
+ Source on GitHub
+
+
+ <% end %>
+
+
+ Entities
+
+
+
+
+
+
+
+
+
+
+ Dependencies
+
+
+ <% if @mint_json.dependencies.each == 0 %>
+
+ No Dependencies
+
+ <% else %>
+ <% @mint_json.dependencies.each do |d|%>
+
+
+ <%= d.name %>
+
+ <%= d.constraint.to_s %>
+
+ <% end %>
+ <% end %>
+
+
+
+
+
+ <%= content %>
+
+
+
+
+
+
+
diff --git a/src/documentation_generator/html/property.ecr b/src/documentation_generator/html/property.ecr
new file mode 100644
index 000000000..1f525e387
--- /dev/null
+++ b/src/documentation_generator/html/property.ecr
@@ -0,0 +1,17 @@
+
+
+
+
+
+ <%= stringify(node) %>
+
+
+ <%= generate(node.type) %>
+
+ <%= default(node) %>
+
+ <%= source_url(node) %>
+
+
+ <%= comment(node) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/provider.ecr b/src/documentation_generator/html/provider.ecr
new file mode 100644
index 000000000..22d27ae75
--- /dev/null
+++ b/src/documentation_generator/html/provider.ecr
@@ -0,0 +1,13 @@
+
+ <%= stringify(node) %>
+
+ <%= source_url(node) %>
+
+
+<%= comment(node) %>
+
+Functions
+
+<% node.functions.sort_by(&.name.value).each do |f| %>
+ <%= generate(f) %>
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/state.ecr b/src/documentation_generator/html/state.ecr
new file mode 100644
index 000000000..1f525e387
--- /dev/null
+++ b/src/documentation_generator/html/state.ecr
@@ -0,0 +1,17 @@
+
+
+
+
+
+ <%= stringify(node) %>
+
+
+ <%= generate(node.type) %>
+
+ <%= default(node) %>
+
+ <%= source_url(node) %>
+
+
+ <%= comment(node) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/store.ecr b/src/documentation_generator/html/store.ecr
new file mode 100644
index 000000000..af0b40b6d
--- /dev/null
+++ b/src/documentation_generator/html/store.ecr
@@ -0,0 +1,16 @@
+
+ <%= stringify(node) %>
+
+
+
+<%= comment(node) %>
+
+States
+
+<% node.states.sort_by(&.name.value).each do |s| %>
+ <%= generate(s) %>
+<% end %>
+
+<% node.functions.sort_by(&.name.value).each do |s| %>
+ <%= generate(s) %>
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/type.ecr b/src/documentation_generator/html/type.ecr
new file mode 100644
index 000000000..41f2d1de9
--- /dev/null
+++ b/src/documentation_generator/html/type.ecr
@@ -0,0 +1,3 @@
+
+ <%= stringify(node) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/type_definition.ecr b/src/documentation_generator/html/type_definition.ecr
new file mode 100644
index 000000000..79664f312
--- /dev/null
+++ b/src/documentation_generator/html/type_definition.ecr
@@ -0,0 +1,11 @@
+
+ <%= stringify(node) %>
+
+ <%= source_url(node) %>
+
+
+Fields
+
+<% node.fields.sort_by{|f| stringify(f) }.each do |f| %>
+ <%= generate(f) %>
+<% end %>
\ No newline at end of file
diff --git a/src/documentation_generator/html/type_definition_field.ecr b/src/documentation_generator/html/type_definition_field.ecr
new file mode 100644
index 000000000..79da2eb06
--- /dev/null
+++ b/src/documentation_generator/html/type_definition_field.ecr
@@ -0,0 +1,13 @@
+
+
+
+
+
+ <%= node.key.value %>
+
+
+ <%= generate(node.type) %>
+
+ <%= source_url(node) %>
+
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/type_variable.ecr b/src/documentation_generator/html/type_variable.ecr
new file mode 100644
index 000000000..5f39a4504
--- /dev/null
+++ b/src/documentation_generator/html/type_variable.ecr
@@ -0,0 +1,5 @@
+
+
+ <%= stringify(node) %>
+
+
\ No newline at end of file
diff --git a/src/documentation_generator/html/type_variant.ecr b/src/documentation_generator/html/type_variant.ecr
new file mode 100644
index 000000000..78362f787
--- /dev/null
+++ b/src/documentation_generator/html/type_variant.ecr
@@ -0,0 +1,21 @@
+
+
+
+ <%= stringify(node) %>
+
+
+ <% if node.parameters.to_a.any? %>
+ (
+
+ <% node.parameters.each do |p| %>
+ <%= generate(p) %>
+ <% end %>
+
+ )
+ <% end %>
+
+ <%= source_url(node) %>
+
+
+ <%= comment(node) %>
+
\ No newline at end of file
diff --git a/src/documentation_generator/id.cr b/src/documentation_generator/id.cr
index 6f89f9405..31c246ab3 100644
--- a/src/documentation_generator/id.cr
+++ b/src/documentation_generator/id.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def stringify(node : Ast::Id)
node.value
end
@@ -8,4 +8,16 @@ module Mint
json.string stringify(node)
end
end
+
+ class DocumentationGeneratorHtml
+ def stringify(node : Ast::Id)
+ url = type_url(node.value)
+
+ if url != ""
+ "#{node.value}"
+ else
+ node.value
+ end
+ end
+ end
end
diff --git a/src/documentation_generator/module.cr b/src/documentation_generator/module.cr
index ab03c122b..6263b2406 100644
--- a/src/documentation_generator/module.cr
+++ b/src/documentation_generator/module.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Module, json : JSON::Builder)
json.object do
json.field "description", node.comment.try(&.to_html)
@@ -13,4 +13,18 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Module)
+ render("#{__DIR__}/html/module.ecr")
+ end
+
+ def stringify(node : Ast::Module)
+ node.name.value
+ end
+
+ def children(node : Ast::Module)
+ children("modules", "function", node, node.functions)
+ end
+ end
end
diff --git a/src/documentation_generator/property.cr b/src/documentation_generator/property.cr
index 30ade7faa..dd35ee819 100644
--- a/src/documentation_generator/property.cr
+++ b/src/documentation_generator/property.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Property, json : JSON::Builder)
json.object do
json.field "default", node.default.try { |item| source(item) }
@@ -9,4 +9,22 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Property)
+ render("#{__DIR__}/html/property.ecr")
+ end
+
+ def stringify(node : Ast::Property)
+ node.name.value
+ end
+
+ def default(node : Ast::Property)
+ render("#{__DIR__}/html/default.ecr")
+ end
+
+ def comment(node : Ast::Property)
+ render("#{__DIR__}/html/comment.ecr")
+ end
+ end
end
diff --git a/src/documentation_generator/provider.cr b/src/documentation_generator/provider.cr
index 8b6a74f0c..3b092ba84 100644
--- a/src/documentation_generator/provider.cr
+++ b/src/documentation_generator/provider.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Provider, json : JSON::Builder)
json.object do
json.field "description", node.comment.try(&.to_html)
@@ -14,4 +14,18 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Provider)
+ render("#{__DIR__}/html/provider.ecr")
+ end
+
+ def stringify(node : Ast::Provider)
+ node.name.value
+ end
+
+ def children(node : Ast::Provider)
+ children("providers", "function", node, node.functions)
+ end
+ end
end
diff --git a/src/documentation_generator/state.cr b/src/documentation_generator/state.cr
index 2862337dc..4a498eb03 100644
--- a/src/documentation_generator/state.cr
+++ b/src/documentation_generator/state.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::State, json : JSON::Builder)
json.object do
json.field "type", node.type.try { |item| stringify(item) }
@@ -9,4 +9,22 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::State)
+ render("#{__DIR__}/html/state.ecr")
+ end
+
+ def stringify(node : Ast::State)
+ node.name.value
+ end
+
+ def default(node : Ast::State)
+ render("#{__DIR__}/html/default.ecr")
+ end
+
+ def comment(node : Ast::State)
+ render("#{__DIR__}/html/comment.ecr")
+ end
+ end
end
diff --git a/src/documentation_generator/store.cr b/src/documentation_generator/store.cr
index 01ab973bd..82284e537 100644
--- a/src/documentation_generator/store.cr
+++ b/src/documentation_generator/store.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Store, json : JSON::Builder)
json.object do
json.field "name" do
@@ -22,4 +22,19 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::Store)
+ render("#{__DIR__}/html/store.ecr")
+ end
+
+ def stringify(node : Ast::Store)
+ node.name.value
+ end
+
+ def children(node : Ast::Store)
+ children("stores", "state", node, node.states) |
+ children("stores", "function", node, node.functions)
+ end
+ end
end
diff --git a/src/documentation_generator/type.cr b/src/documentation_generator/type.cr
index da466520a..39bd0713c 100644
--- a/src/documentation_generator/type.cr
+++ b/src/documentation_generator/type.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def stringify(node : Ast::Type)
parameters =
unless node.parameters.empty?
@@ -13,4 +13,23 @@ module Mint
json.string stringify(node)
end
end
+
+ class DocumentationGeneratorHtml
+ def stringify(node : Ast::Type)
+ parameters =
+ unless node.parameters.empty?
+ "(#{stringify(node.parameters)})"
+ end
+
+ "#{stringify node.name}#{parameters}"
+ end
+
+ def generate(node : Ast::Type | Nil)
+ if node
+ render("#{__DIR__}/html/type.ecr")
+ else
+ ""
+ end
+ end
+ end
end
diff --git a/src/documentation_generator/type_definition.cr b/src/documentation_generator/type_definition.cr
index 585704538..f130674cb 100644
--- a/src/documentation_generator/type_definition.cr
+++ b/src/documentation_generator/type_definition.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::TypeDefinition, json : JSON::Builder)
json.object do
json.field "description", node.comment.try(&.to_html)
@@ -13,4 +13,14 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::TypeDefinition)
+ render("#{__DIR__}/html/type_definition.ecr")
+ end
+
+ def stringify(node : Ast::TypeDefinition)
+ node.name.value
+ end
+ end
end
diff --git a/src/documentation_generator/type_definition_field.cr b/src/documentation_generator/type_definition_field.cr
index a7daa1bb7..3d92fab29 100644
--- a/src/documentation_generator/type_definition_field.cr
+++ b/src/documentation_generator/type_definition_field.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::TypeDefinitionField, json : JSON::Builder)
json.object do
json.field "key", node.key.value
@@ -8,4 +8,14 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::TypeDefinitionField)
+ render("#{__DIR__}/html/type_definition_field.ecr")
+ end
+
+ def stringify(node : Ast::TypeDefinitionField)
+ node.key.value
+ end
+ end
end
diff --git a/src/documentation_generator/type_variable.cr b/src/documentation_generator/type_variable.cr
index 61f115780..93c599a64 100644
--- a/src/documentation_generator/type_variable.cr
+++ b/src/documentation_generator/type_variable.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def stringify(node : Ast::TypeVariable)
node.value
end
@@ -8,4 +8,14 @@ module Mint
json.string node.value
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::TypeVariable)
+ render("#{__DIR__}/html/type_variable.ecr")
+ end
+
+ def stringify(node : Ast::TypeVariable)
+ node.value
+ end
+ end
end
diff --git a/src/documentation_generator/type_variant.cr b/src/documentation_generator/type_variant.cr
index eb40c1317..e9b1dfabb 100644
--- a/src/documentation_generator/type_variant.cr
+++ b/src/documentation_generator/type_variant.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::TypeVariant, json : JSON::Builder)
json.object do
json.field "description", node.comment.try(&.to_html)
@@ -13,4 +13,18 @@ module Mint
end
end
end
+
+ class DocumentationGeneratorHtml
+ def generate(node : Ast::TypeVariant)
+ render("#{__DIR__}/html/type_variant.ecr")
+ end
+
+ def comment(node : Ast::TypeVariant)
+ render("#{__DIR__}/html/comment.ecr")
+ end
+
+ def stringify(node : Ast::TypeVariant)
+ node.value.value
+ end
+ end
end
diff --git a/src/documentation_generator/use.cr b/src/documentation_generator/use.cr
index c5bcfbdaf..5fa7d29f1 100644
--- a/src/documentation_generator/use.cr
+++ b/src/documentation_generator/use.cr
@@ -1,5 +1,5 @@
module Mint
- class DocumentationGenerator
+ class DocumentationGeneratorJson
def generate(node : Ast::Use, json : JSON::Builder)
condition =
node.condition.try do |expression|
diff --git a/src/documentation_server.cr b/src/documentation_server.cr
index 740c855f7..3f2f7704f 100644
--- a/src/documentation_server.cr
+++ b/src/documentation_server.cr
@@ -3,7 +3,7 @@ module Mint
@asts = {} of MintJson => Ast
@error : String?
@ast = Ast.new
- @generator = DocumentationGenerator.new
+ @generator = DocumentationGeneratorJson.new
def self.start
new
diff --git a/src/mint_json.cr b/src/mint_json.cr
index e14bc325d..1fdaa23ed 100644
--- a/src/mint_json.cr
+++ b/src/mint_json.cr
@@ -31,6 +31,7 @@ module Mint
getter application = Application.new
getter root : String
getter name = ""
+ getter source_url = ""
def initialize(@json : String, @root : String, @file : String)
begin
@@ -150,10 +151,12 @@ module Mint
parse_external_assets
when "web-components"
parse_web_components
+ when "source-url"
+ parse_source_url
else
error! :mint_json_root_invalid_key do
block do
- text "The root object of a"
+ text "The root object in the"
bold "mint.json"
text "file has an invalid key:"
bold key
@@ -189,7 +192,7 @@ module Mint
block do
text "The"
bold "name"
- text "field of a"
+ text "field in the"
bold "mint.json"
text "file is empty:"
end
@@ -201,7 +204,7 @@ module Mint
block do
text "The"
bold "name"
- text "field of a"
+ text "field in the"
bold "mint.json"
text "file is not a string."
end
@@ -224,7 +227,7 @@ module Mint
block do
text "The"
bold "mint-version"
- text "field in your"
+ text "field in the"
bold "mint.json"
text "file is empty."
end
@@ -268,7 +271,7 @@ module Mint
block do
text "The"
bold "mint-version"
- text "field in your"
+ text "field in the"
bold "mint.json"
text "file does not match your current version of Mint."
end
@@ -289,7 +292,7 @@ module Mint
block do
text "The"
bold "mint-version"
- text "field in your"
+ text "field in the"
bold "mint.json"
text "file is not a string."
end
@@ -690,7 +693,7 @@ module Mint
block do
text "The"
bold "formatter-config"
- text "object of a"
+ text "object in the"
bold "mint.json"
text "file has an invalid key:"
bold key
@@ -793,7 +796,7 @@ module Mint
block do
text "The"
bold "application object"
- text "of a"
+ text "in the"
bold "mint.json"
text "file has an invalid key:"
bold key
@@ -1176,6 +1179,29 @@ module Mint
end
end
+ def parse_source_url
+ location =
+ @parser.location
+
+ @source_url =
+ @parser.read_string
+
+ user, repo = SourceUrl.parse_user_and_repo(@source_url)
+
+ error! :mint_json_source_url_invalid do
+ block do
+ text "The"
+ bold "source-url"
+ text "field in the"
+ bold "mint.json"
+ text "has an invalid format, must be"
+ bold "https://domain/user/repo:"
+ end
+
+ snippet node(location)
+ end if user.empty? || repo.empty?
+ end
+
def check_dependencies!
dependencies.each do |dependency|
next if dependency_exists?(dependency.name)
diff --git a/src/semantic_tokenizer.cr b/src/semantic_tokenizer.cr
index 96e5eee6a..98e159738 100644
--- a/src/semantic_tokenizer.cr
+++ b/src/semantic_tokenizer.cr
@@ -67,9 +67,18 @@ module Mint
end
def self.highlight(path : String, html : Bool = false)
- ast =
- Parser.parse(path)
+ ast = Parser.parse(path)
+ highlight(ast, html)
+ end
+
+ def self.highlight(text : String, file : String, html : Bool = false)
+ ast = Parser.parse(text, file)
+
+ highlight(ast, html)
+ end
+
+ def self.highlight(ast : Ast, html : Bool = false)
parts =
tokenize(ast)
diff --git a/src/utils/source_url.cr b/src/utils/source_url.cr
new file mode 100644
index 000000000..7a0a533c3
--- /dev/null
+++ b/src/utils/source_url.cr
@@ -0,0 +1,11 @@
+module Mint
+ class SourceUrl
+ def self.parse_user_and_repo(url : String) : Tuple(String, String)
+ if /[https?:\/\/]?(.*)\.(.*)\/(.*)\/(.*)\/?/.match(url)
+ {$3, $4}
+ else
+ {"", ""}
+ end
+ end
+ end
+end