documentation-editor 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b8c28c703d26a40895931e759db26f895b04ce4
4
- data.tar.gz: be2dfdb433d3806ff42428404dfd0e902ee49265
3
+ metadata.gz: de3dc4291b2f0215d3e0021c5cfe95060b8f178c
4
+ data.tar.gz: efd354eebc831c9faf0898a5b18930bc244fea6c
5
5
  SHA512:
6
- metadata.gz: 0deaaf80b2666390ea8c82aa41dd1d2a6291c307d029bff67c07a0e333a93857dd03b0f1d31e8fa10935eb1e3b54c6ac3bdf09ffb22f3eb7259a5caca1406fe8
7
- data.tar.gz: 50d160d60e6172540e4bb2f9879c8f33214e98580f1085cbd4a5c3665e5a6a46a4aa596e4acb3e657902b45cd42a4de7281b267d4e0b3a287196f41fd5ddff2b
6
+ metadata.gz: a085cab90f82e21f8b12608797dad347b01cb3f34d808e446482f997669ab7e87fc0cb470585569207afab4e81d9b603845f086d36fa07c548ee8552a0909005
7
+ data.tar.gz: 61bbd321089e9b6fed435cb6b9f2e99616cdd243dfa998e834f2cc3baf336ff131d2fc9237c616023ee7edbdf40ebd532792c410340eb1b302a70a6614e66ee1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Documentation Editor
2
2
 
3
- [![Build Status](https://travis-ci.org/algolia/documentation-editor.png?branch=master)](https://travis-ci.org/algolia/documentation-editor) [![Gem Version](https://badge.fury.io/rb/documentaton-editor.png)](http://badge.fury.io/rb/documentation-editor)
3
+ [![Build Status](https://travis-ci.org/algolia/documentation-editor.png?branch=master)](https://travis-ci.org/algolia/documentation-editor) [![Gem Version](https://badge.fury.io/rb/documentation-editor.svg)](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
- ## Markdown Extensions
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.
@@ -61,6 +61,7 @@ module DocumentationEditor
61
61
  @page = Page.find_by!(slug: params[:slug])
62
62
  @revision = @page.published_revision
63
63
  @options = params
64
+ @base_path = params[:section] ? request.path.split('/sections/').first : request.path
64
65
  render :preview
65
66
  end
66
67
 
@@ -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
- item = { label: text, id: generate_id(doc, child.options[:raw_text]), children: [], level: child.options[:level] }
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
- sections << current_section unless current_section.select { |c| c.type != :blank }.empty?
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 generate_id(doc, str)
92
- @html_converter ||= Kramdown::Converter::Html.send(:new, doc.root, {auto_id_prefix: ''})
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)
@@ -1,6 +1,6 @@
1
1
  %ul.nav
2
2
  - menu_items.each do |menu|
3
3
  %li
4
- = link_to menu[:label], "##{menu[:id]}"
4
+ = link_to menu[:label], "#{menu[:h1] == params[:section] ? '' : @base_path}##{menu[:id]}"
5
5
  - if menu[:children].size > 0
6
6
  = render partial: 'menu_items', object: menu[:children]
@@ -13,4 +13,4 @@
13
13
  Edit
14
14
  - cache("page-#{id}-content") do
15
15
  = find_and_preserve do
16
- = @revision.to_html(@options).html_safe
16
+ = @revision.to_html(@options.merge(section: params[:section])).html_safe
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
@@ -1,3 +1,3 @@
1
1
  module DocumentationEditor
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  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.2.1
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-18 00:00:00.000000000 Z
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.4.5
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