documentation-editor 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/app/controllers/documentation_editor/pages_controller.rb +1 -0
- data/app/models/documentation_editor/revision.rb +15 -6
- data/app/views/documentation_editor/pages/_menu_items.html.haml +1 -1
- data/app/views/documentation_editor/pages/preview.html.haml +1 -1
- data/config/routes.rb +1 -0
- data/lib/documentation_editor/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de3dc4291b2f0215d3e0021c5cfe95060b8f178c
|
4
|
+
data.tar.gz: efd354eebc831c9faf0898a5b18930bc244fea6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a085cab90f82e21f8b12608797dad347b01cb3f34d808e446482f997669ab7e87fc0cb470585569207afab4e81d9b603845f086d36fa07c548ee8552a0909005
|
7
|
+
data.tar.gz: 61bbd321089e9b6fed435cb6b9f2e99616cdd243dfa998e834f2cc3baf336ff131d2fc9237c616023ee7edbdf40ebd532792c410340eb1b302a70a6614e66ee1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Documentation Editor
|
2
2
|
|
3
|
-
[](https://travis-ci.org/algolia/documentation-editor) [](https://travis-ci.org/algolia/documentation-editor) [](http://badge.fury.io/rb/documentation-editor)
|
4
4
|
|
5
5
|
This is the mountable Rails application providing the documentation editor of [algolia.com/doc](https://www.algolia.com/doc).
|
6
6
|
|
@@ -117,7 +117,7 @@ DocumentationEditor::Config.paperclip_options = {
|
|
117
117
|
DocumentationEditor::Config.wrap_h1_with_sections = true
|
118
118
|
```
|
119
119
|
|
120
|
-
##
|
120
|
+
## Extensions
|
121
121
|
|
122
122
|
#### Language conditions
|
123
123
|
|
@@ -155,6 +155,17 @@ Use `[[variable:VARIABLE]]` and specify any variables you want to display their
|
|
155
155
|
This is the value of the `name` variable: [[variable:name]].
|
156
156
|
```
|
157
157
|
|
158
|
+
#### Section Restriction
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Rails.application.routes.draw do
|
162
|
+
get '/doc/ruby(/:section)', :controller => 'pages', :action => 'show', slug: 'my_page'
|
163
|
+
mount DocumentationEditor::Engine => "/doc"
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
If you're using the `wrap_h1_with_sections` option you can use the `:section` param to restrict the rendering to a specific section your page. The TOC will still contain everything. That's something you may want to use for SEO reasons.
|
168
|
+
|
158
169
|
## Usage
|
159
170
|
|
160
171
|
Create your first page from the `/doc/admin` URL.
|
@@ -17,12 +17,16 @@ module DocumentationEditor
|
|
17
17
|
def to_toc(options = {})
|
18
18
|
roots = []
|
19
19
|
levels = []
|
20
|
+
h1 = nil
|
20
21
|
doc = parse_document(options.merge(no_wrap: true))
|
22
|
+
ids = id_generator(doc)
|
21
23
|
doc.root.children.each do |child|
|
22
24
|
next if child.type != :header
|
23
25
|
text = child.options[:raw_text]
|
24
26
|
text = resolve_variables(options, text)
|
25
|
-
|
27
|
+
id = ids.generate_id(text)
|
28
|
+
h1 = id if child.options[:level] == 1
|
29
|
+
item = { label: text, id: id, children: [], level: child.options[:level], h1: h1 }
|
26
30
|
while !levels.empty? && levels.last[:level] >= child.options[:level]
|
27
31
|
levels.pop
|
28
32
|
end
|
@@ -47,14 +51,20 @@ module DocumentationEditor
|
|
47
51
|
if !options[:no_wrap] && DocumentationEditor::Config.wrap_h1_with_sections
|
48
52
|
sections = []
|
49
53
|
current_section = []
|
54
|
+
h1 = nil
|
55
|
+
ids = id_generator(doc)
|
56
|
+
keep = options[:section].nil?
|
50
57
|
doc.root.children.each do |child|
|
51
58
|
if child.type == :header && child.options[:level] == 1 && !current_section.select { |c| c.type != :blank }.empty?
|
52
|
-
sections << current_section
|
59
|
+
sections << current_section if keep
|
53
60
|
current_section = []
|
61
|
+
keep = options[:section].nil? || options[:section] == ids.generate_id(resolve_variables(options, child.options[:raw_text]))
|
54
62
|
end
|
55
63
|
current_section << child
|
56
64
|
end
|
57
|
-
|
65
|
+
if !current_section.select { |c| c.type != :blank }.empty? && keep
|
66
|
+
sections << current_section
|
67
|
+
end
|
58
68
|
doc.root.children = sections.map do |nested_sections|
|
59
69
|
section = Kramdown::Element.new(:html_element, 'section')
|
60
70
|
section.children = nested_sections
|
@@ -88,9 +98,8 @@ module DocumentationEditor
|
|
88
98
|
end.compact
|
89
99
|
end
|
90
100
|
|
91
|
-
def
|
92
|
-
|
93
|
-
@html_converter.generate_id(str)
|
101
|
+
def id_generator(doc)
|
102
|
+
Kramdown::Converter::Html.send(:new, doc.root, {auto_id_prefix: ''})
|
94
103
|
end
|
95
104
|
|
96
105
|
def resolve_variables(options, text)
|
data/config/routes.rb
CHANGED
@@ -16,5 +16,6 @@ DocumentationEditor::Engine.routes.draw do
|
|
16
16
|
get '/:id/versions', :controller => 'pages', :action => 'versions'
|
17
17
|
end
|
18
18
|
|
19
|
+
get '/:slug/sections/:section', as: :section, :controller => 'pages', :action => 'show', constraints: { slug: /.*/ }
|
19
20
|
get '/:slug', as: :page, :controller => 'pages', :action => 'show', constraints: { slug: /.*/ }
|
20
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: documentation-editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.2.2
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Mountable Rails application providing an extended Markdown documentation
|