Просмотр исходного кода

templates: quick work to add edit/create button in generated html pages

David Bernard 9 лет назад
Родитель
Сommit
bff1883b06

+ 3 - 1
build.gradle

@@ -19,7 +19,7 @@ asciidoctor {
 		from('src/docs/resources')
 	}
 	attributes 'build-gradle': file('build.gradle'),
-		'sourcedir': project.sourceSets.main.java.srcDirs[0],
+		'sourcedir': project.asciidoctor.sourceDir,
 		'endpoint-url': 'https://jmonkeyengine.github.io/wiki',
 		'source-highlighter' : 'coderay',
 		'linkcss': 'true',
@@ -30,6 +30,8 @@ asciidoctor {
 		'idprefix':'',
 		'idseparator':'-',
 		'docinfo1':'true',
+		'wiki_link_edit_prefix': 'https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc',
+		'wiki_link_create_prefix': 'https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc',
 		'orgname':'jMonkeyEngine'
 	options header_footer: true,
 		template_dirs: [file('src/templates/slim').absolutePath]

+ 1 - 0
src/templates/slim/html5/_toc.html.slim

@@ -1,4 +1,5 @@
 #toc class=(attr 'toc-class', 'toc')
+  include _tools.html
   #toctitle =(attr 'toc-title')
   / Renders block_outline.html.
   = converter.convert document, 'outline'

+ 5 - 0
src/templates/slim/html5/_tools.html.slim

@@ -0,0 +1,5 @@
+#toolbar
+  a href=wiki_link_edit()
+    i class="fa fa-plus-square" aria-hidden="true"
+  a href=wiki_link_create()
+    i class="fa fa-pencil-square" aria-hidden="true"

+ 18 - 0
src/templates/slim/html5/helpers.rb

@@ -529,4 +529,22 @@ module Slim::Helpers
       (%(fa-flip-#{attr :flip}) if attr? :flip)
     ].compact
   end
+
+  # wiki_links
+
+  def source_relative_path(file)
+    file[document.attr('sourcedir', '').length..-1]
+    #file - document.attr('sourcedir', '')
+  end
+
+  def wiki_link_edit()
+    document.attr('wiki_link_edit_prefix', 'wikiedit') + source_relative_path(document.attr('docfile', ''))
+  end
+
+  def wiki_link_create()
+    path =source_relative_path(document.attr('docfile', ''))
+    path = path[0..path.rindex('/')] # parent directory
+    document.attr('wiki_link_create_prefix', 'wikicreate')  + path
+  end
+
 end