Skip to content

Commit

Permalink
Merge: src/doc/commands: clean commands hierarchy
Browse files Browse the repository at this point in the history
This PR does some cleaning around commands hierarchy to prepare for the merge with new-markdown (#2720).

Pull-Request: #2723
  • Loading branch information
privat committed Jun 26, 2018
2 parents 469e5f2 + b67f694 commit c4a9d0b
Show file tree
Hide file tree
Showing 131 changed files with 593 additions and 612 deletions.
2 changes: 1 addition & 1 deletion lib/html/bootstrap.nit
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Link
redef fun rendering do
add "<a{render_css_classes} href=\"{href}\""
var title = self.title
if title != null then add " title=\"{title.write_to_string}\""
if title != null then add " title=\"{title.html_escape}\""
add ">{text}</a>"
end
end
Expand Down
18 changes: 0 additions & 18 deletions src/catalog/catalog.nit
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,6 @@ class Person
return email.md5.to_lower
end

# Return a full-featured link to a person
fun to_html: String
do
var res = ""
var e = name.html_escape
var page = self.page
if page != null then
res += "<a href=\"{page.html_escape}\">"
end
var gravatar = self.gravatar
if gravatar != null then
res += "<img src=\"https://secure.gravatar.com/avatar/{gravatar}?size=20&amp;default=retro\">&nbsp;"
end
res += e
if page != null then res += "</a>"
return res
end

# The standard representation of a person.
#
# ~~~
Expand Down
85 changes: 0 additions & 85 deletions src/catalog/catalog_json.nit

This file was deleted.

5 changes: 3 additions & 2 deletions src/doc/api/api_base.nit
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import popcorn::pop_repos
import popcorn::pop_json

import commands::commands_http
import commands::commands_json
import commands::commands_html

import templates::json_commands
import templates::html_commands

# Nitweb config file.
class NitwebConfig
Expand Down
1 change: 0 additions & 1 deletion src/doc/commands/commands_base.nit
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
module commands_base

import model::model_index
import catalog

# Documentation command
#
Expand Down
1 change: 1 addition & 0 deletions src/doc/commands/commands_catalog.nit
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
module commands_catalog

import commands_model
import catalog

# A DocCommand based on a Catalog
abstract class CmdCatalog
Expand Down
115 changes: 3 additions & 112 deletions src/doc/commands/commands_docdown.nit
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
# Doc down related queries
module commands_docdown

import commands::commands_parser
import commands::commands_html

intrude import doc_down
intrude import markdown::wikilinks
import templates::md_commands
import markdown

# Retrieve the MDoc summary
#
Expand All @@ -28,7 +25,7 @@ class CmdSummary
super CmdComment

# Markdown processor used to parse the headlines
var markdown_processor: nullable MarkdownProcessor = null is optional, writable
var markdown_processor: MarkdownProcessor is writable

# Resulting summary
#
Expand All @@ -40,12 +37,6 @@ class CmdSummary
if not res isa CmdSuccess then return res
var mentity = self.mentity.as(not null)

var markdown_processor = self.markdown_processor
if markdown_processor == null then
markdown_processor = new MarkdownProcessor
self.markdown_processor = markdown_processor
end

var mdoc = self.mdoc
if mdoc == null then
mdoc = if fallback then mentity.mdoc_or_fallback else mentity.mdoc
Expand All @@ -61,103 +52,3 @@ class CmdSummary
return res
end
end

# Custom Markdown processor able to process doc commands
class CmdDecorator
super NitdocDecorator

redef type PROCESSOR: CmdMarkdownProcessor

# Model used by wikilink commands to find entities
var model: Model

# Filter to apply if any
var filter: nullable ModelFilter

redef fun add_span_code(v, buffer, from, to) do
var text = new FlatBuffer
buffer.read(text, from, to)
var name = text.write_to_string
name = name.replace("nullable ", "")
var mentity = try_find_mentity(name)
if mentity == null then
super
else
v.add "<code>"
v.emit_text mentity.html_link.write_to_string
v.add "</code>"
end
end

private fun try_find_mentity(text: String): nullable MEntity do
var mentity = model.mentity_by_full_name(text, filter)
if mentity != null then return mentity

var mentities = model.mentities_by_name(text, filter)
if mentities.is_empty then
return null
else if mentities.length > 1 then
# TODO smart resolve conflicts
end
return mentities.first
end

redef fun add_wikilink(v, token) do
v.render_wikilink(token, model)
end
end

# Same as `InlineDecorator` but with wikilink commands handling
class CmdInlineDecorator
super InlineDecorator

redef type PROCESSOR: CmdMarkdownProcessor

# Model used by wikilink commands to find entities
var model: Model

redef fun add_wikilink(v, token) do
v.render_wikilink(token, model)
end
end

# Custom MarkdownEmitter for commands
class CmdMarkdownProcessor
super MarkdownProcessor

# Parser used to process doc commands
var parser: CommandParser

# Render a wikilink
fun render_wikilink(token: TokenWikiLink, model: Model) do
var link = token.link
if link == null then return
var name = token.name
if name != null then link = "{name} | {link}"

var command = parser.parse(link.write_to_string)
var error = parser.error

if error isa CmdError then
emit_text error.to_html.write_to_string
return
end
if error isa CmdWarning then
emit_text error.to_html.write_to_string
end
add command.as(not null).to_html
end
end

redef class Text
# Read `self` between `nstart` and `nend` (excluded) and writte chars to `out`.
private fun read(out: FlatBuffer, nstart, nend: Int): Int do
var pos = nstart
while pos < length and pos < nend do
out.add self[pos]
pos += 1
end
if pos == length then return -1
return pos
end
end
8 changes: 6 additions & 2 deletions src/doc/commands/commands_http.nit
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
# To be more generic, param names should be extracted as variables.
module commands_http

import commands
import commands::commands_catalog
import commands_catalog
import commands_graph
import commands_ini
import commands_main
import commands_usage

import nitcorn::vararg_routes

redef class DocCommand
Expand Down
2 changes: 1 addition & 1 deletion src/doc/commands/commands_ini.nit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

module commands_ini

import doc::commands::commands_model
import commands_model

# Cmd that finds the ini file related to an `mentity`
abstract class CmdIni
Expand Down
2 changes: 1 addition & 1 deletion src/doc/commands/commands_main.nit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

module commands_main

import doc::commands::commands_model
import commands_model

# Cmd that finds the mains of an `mentity`
class CmdMains
Expand Down
Loading

0 comments on commit c4a9d0b

Please sign in to comment.