Skip to content

Commit

Permalink
Added Docs engine
Browse files Browse the repository at this point in the history
  • Loading branch information
kisenka committed Feb 12, 2015
1 parent e247d36 commit c3082ea
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_site
_includes/page.html
app
HelpTOC.json
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CONFIG = {
:source_dir => __dir__,
:tmp_dir => "#{__dir__}/_tmp",
:build_destination => "_site",
:preview_host => "0.0.0.0",
:preview_port => 4000,
:default_env => 'dev'
}

Dir['_rake/*.rake'].each { |r| load r }

task :default do
system('rake -T')
end
10 changes: 10 additions & 0 deletions _SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Similar to GitBook SUMMARY.md - https://github.com/GitbookIO/gitbook#summarymd,
but list items without links will not br included in the table of contents.
Also you can use HTML-comments.
-->

## Getting started
* [Getting started with SDK](index.html)
* Some planned topic
<!-- * [Another planned topic](topic.html) -->
22 changes: 22 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
product_name: IntelliJ SDK
product_version:

markdown: kramdown
markdown_ext: foo
kramdown:
input: GFM2
hard_wrap: false
auto_ids: false
highlighter: pygments

exclude:
- '*.scss'
- README*
- Rakefile
- lib
- webhelp-template
- code_samples

defaults:
- values:
layout: 'webhelp'
5 changes: 5 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</title>
<link rel="stylesheet" href="styles/styles.css">
32 changes: 32 additions & 0 deletions _layouts/webhelp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% capture _t %}
{% assign product_name = site.product_name %}
{% assign product_version = site.product_version %}
{% assign page_title = page.title %}
{% assign page_title_with_h1 = '' %}
{% assign page_id = page.name | replace:'.md','' %}
{% assign page_content = content %}
{% capture shortcut_switcher %}
<div class="shortcuts-switcher"><label for="switch-shortcuts">Keymap:</label><select id="switch-shortcuts" class="select _shortcuts" height="1">
<option data-group="primary" value="default" selected>Default</option>
<option data-group="primary" value="default_for_gnome">GNOME</option>
<option data-group="primary" value="default_for_kde">KDE</option>
<option data-group="primary" value="default_for_xwin">XWindow</option>
<option data-group="primary" value="emacs">Emacs</option>
<option data-group="primary" value="jbuilder">JBuilder</option>
<option data-group="primary" value="visual_studio">Visual Studio</option>
<option data-group="primary" value="netbeans_6.5">NetBeans 6.5</option>
<option data-group="primary" value="eclipse">Eclipse</option>
<option data-group="secondary" value="mac_os_x_10.5_">OS X 10.5+</option>
<option data-group="secondary" value="mac_os_x">OS X</option>
<option data-group="secondary" value="eclipse_mac_os_x">OS X Eclipse</option></select>
</div>
{% endcapture %}
{% assign is_show_shortcut_switcher = 'false' %}
{% assign current_year = 'now' | date:'%Y' %}
{% assign last_modified = '' %}
{% assign disqus = '' %}
{% assign baseurl = '.' %}

{% endcapture %}
{% capture rendered_content %}{% include page.html %}{% endcapture %}
{{ rendered_content | replace:'</head>','<link rel="stylesheet" href="styles/styles.css"></head>' }}
154 changes: 154 additions & 0 deletions _plugins/markdown_converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
require 'kramdown'
require 'pygments'

module Kramdown
module Converter
class Upsrc < Html

def convert_header(el, indent)
attr = el.attr.dup
el_id = generate_id(el.options[:raw_text])

if @options[:auto_ids] && !attr['id']
attr['id'] = el_id
end
@toc << [el.options[:level], attr['id'], el.children] if attr['id'] && in_toc?(el)
level = output_header_level(el.options[:level])

if level <= 3
anchor = Element.new(:a, nil, {'href' => '#' + el_id, 'class' => 'anchor-link'})
el.children.push(anchor)
end

anchor = format_as_block_html("a", {'name' => el_id, 'class' => 'elem-anchor'}, inner(Element.new(:a, nil), indent), indent)
header = format_as_block_html("h#{level}", attr, inner(el, indent), indent)
anchor + header
end

def convert_codeblock(el, indent)
attr = el.attr.dup
lang = self.extract_code_language(attr) || 'text'
highlight_lines = ''

if attr['class'] and attr['class'].scan(/\{[\d\-\,]+\}/).length > 0
lang_parts = attr['class'].split('{')
highlight_lines = "{#{lang_parts[1]}"
end

code = pygmentize(el.value, lang, highlight_lines)
code_attr = {}
code_attr['class'] = "code-block__wrapper"
code_attr['class'] += " code-block _highlighted lang_#{lang}" if lang

"<pre><code#{html_attributes(code_attr)}>#{code}</code></pre>\n"
end

# Extract the code block/span language from the attributes.
def extract_code_language(attr)
if attr['class']
class_attr = attr['class']

if class_attr.scan(/\{|\}/).length > 0
class_attr = class_attr.split('{')[0]
end

class_attr.scan(/\blanguage-(\w+)\b/).first.first
end
end

def convert_codespan(el, indent)
attr = el.attr.dup
lang = extract_code_language!(attr) || 'text'
code = pygmentize(el.value, lang)
attr['class'] = 'code'
attr['class'] += " highlight language-#{lang}" if lang
"<code#{html_attributes(attr)}>#{code}</code>"
end

def convert_blockquote(el, indent)
format_as_indented_block_html(el.type, el.attr, inner(el, indent), indent)
end

def convert_a(el, indent)
res = inner(el, indent)
attr = el.attr.dup
attr['href'] = '' if attr['href'].nil?
is_external = attr['href'].start_with?('http://', 'https://', 'ftp://', '//')
attr['data-bypass'] = 'yes' if is_external
if attr['href'].start_with?('mailto:')
mail_addr = attr['href'][7..-1]
attr['href'] = obfuscate('mailto') << ":" << obfuscate(mail_addr)
res = obfuscate(res) if res == mail_addr
end
format_as_span_html(el.type, attr, "<span>#{res}</span>")
end

def convert_img(el, indent)
"<img#{html_attributes(el.attr)} />"
end

def pygmentize(code, lang, highlight_lines = nil)
hl_lines = ''

if highlight_lines
hl_lines = highlight_lines.gsub(/[{}]/, '').split(',').map do |ln|
if matches = /(\d+)-(\d+)/.match(ln)
ln = Range.new(matches[1], matches[2]).to_a.join(' ')
end
ln
end.join(' ')
end

if lang
Pygments.highlight(code,
:lexer => lang,
:options => {
:encoding => 'utf-8',
:nowrap => true,
:hl_lines => hl_lines
}
)
else
escape_html(code)
end
end
end
end

module Parser
class GFM2 < GFM
def parse
super
end

FENCED_CODEBLOCK_MATCH = /^(([~`]){3,})\s*?(\w+[\{\}\,\d\-]*?)?\s*?\n(.*?)^\1\2*\s*?\n/m
end
end

end

module Jekyll
class KramdownPygments < Jekyll::Converter
def matches(ext)
ext =~ /^\.md$/i
end

def output_ext(ext)
".html"
end

def convert(content)
html = Kramdown::Document.new(content, {
:auto_ids => @config['kramdown']['auto_ids'],
:footnote_nr => @config['kramdown']['footnote_nr'],
:hard_wrap => @config['kramdown']['hard_wrap'],
:entity_output => @config['kramdown']['entity_output'],
:toc_levels => @config['kramdown']['toc_levels'],
:smart_quotes => @config['kramdown']['smart_quotes'],
:coderay_default_lang => @config['kramdown']['default_lang'],
:input => @config['kramdown']['input']
}).to_upsrc
return html
end
end
end
10 changes: 10 additions & 0 deletions _rake/build.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
desc 'Build docs'
task :build do
dest = ENV['dest'] || CONFIG[:build_destination]

Rake::Task['build_toc'].invoke
Rake::Task['prepare_assets'].invoke

command = "jekyll build --trace --destination=#{dest}"
sh command
end
13 changes: 13 additions & 0 deletions _rake/build_toc.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
desc 'Build docs table of contents index'
task :build_toc do
src_dir = CONFIG[:source_dir]
toc_file = ENV['dest'] || "#{src_dir}/HelpTOC.json"

load "#{src_dir}/lib/toc_generator.rb"

kramdown_config = YAML::load_file("#{src_dir}/_config.yml")['kramdown']
toc = Docs::TocGenerator.extract("#{src_dir}/_SUMMARY.md", kramdown_config)

res = File.write("#{toc_file}", toc.to_json)
puts "TOC successfully created in #{toc_file}" if res
end
22 changes: 22 additions & 0 deletions _rake/prepare_assets.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
desc 'Preparing assets'
task :prepare_assets do
dest = ENV["dest"] || CONFIG[:build_destination]
appsrc = 'webhelp-template/app'
appdest = 'app'

# webhelp template
RakeFileUtils.cp 'webhelp-template/app/templates/page.html', '_includes'

# assets dir
RakeFileUtils.mkdir_p %W(#{appdest}/css #{appdest}/fonts #{appdest}/img #{appdest}/js/vendor/requirejs)

# js
RakeFileUtils.cp_r "#{appsrc}/js/main.build.js", "#{appdest}/js"
RakeFileUtils.cp_r "#{appsrc}/js/vendor/requirejs/require.js", "#{appdest}/js/vendor/requirejs"

# css
RakeFileUtils.cp_r "#{appsrc}/css/styles.min.css", "#{appdest}/css"

# images & fonts
RakeFileUtils.cp_r %W(#{appsrc}/fonts #{appsrc}/img), appdest
end
11 changes: 11 additions & 0 deletions _rake/preview.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
desc "Runs site on a local preview webserver"
task :preview do
host = ENV["host"] || CONFIG[:preview_host]
port = ENV["port"] || CONFIG[:preview_port]

Rake::Task["build_toc"].invoke
Rake::Task['prepare_assets'].invoke

command = "jekyll serve --trace --host=#{host} --port=#{port} --watch --force_polling"
sh command
end
8 changes: 8 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Getting started
---

# {{ page.title }}

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus doloremque enim explicabo fugiat modi, obcaecati
officia sunt unde. A assumenda dolorum hic, in ipsam nisi officia porro praesentium provident sequi.
Loading

0 comments on commit c3082ea

Please sign in to comment.