documentation 0.0.1 → 1.0.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/documentation/link.svg +28 -0
  3. data/app/assets/images/documentation/logo-black.svg +23 -0
  4. data/app/assets/images/documentation/logo-white.svg +23 -0
  5. data/app/assets/images/documentation/page.svg +16 -0
  6. data/app/assets/images/documentation/pin.svg +15 -0
  7. data/app/assets/images/documentation/recommendation.svg +11 -0
  8. data/app/assets/images/documentation/search.svg +10 -0
  9. data/app/assets/images/documentation/unhappy.svg +15 -0
  10. data/app/assets/images/documentation/warning.svg +16 -0
  11. data/app/assets/javascripts/documentation/application.coffee +14 -0
  12. data/app/assets/javascripts/documentation/jquery-ui.js +4146 -0
  13. data/app/assets/javascripts/documentation/jquery.autosize.js +263 -0
  14. data/app/assets/stylesheets/documentation/application.scss +320 -0
  15. data/app/assets/stylesheets/documentation/markdown.scss +168 -0
  16. data/app/assets/stylesheets/documentation/page_form.scss +38 -0
  17. data/app/assets/stylesheets/documentation/reset.scss +101 -0
  18. data/app/controllers/documentation/application_controller.rb +21 -0
  19. data/app/controllers/documentation/pages_controller.rb +74 -0
  20. data/app/helpers/documentation/application_helper.rb +13 -0
  21. data/app/models/documentation/page.rb +213 -0
  22. data/app/views/documentation/pages/_admin_buttons.html.haml +18 -0
  23. data/app/views/documentation/pages/form.html.haml +12 -0
  24. data/app/views/documentation/pages/index.html.haml +13 -0
  25. data/app/views/documentation/pages/positioning.html.haml +22 -0
  26. data/app/views/documentation/pages/search.html.haml +26 -0
  27. data/app/views/documentation/pages/show.html.haml +14 -0
  28. data/app/views/documentation/shared/access_denied.html.haml +10 -0
  29. data/app/views/documentation/shared/not_found.html.haml +10 -0
  30. data/app/views/layouts/documentation/_header.html.haml +3 -0
  31. data/app/views/layouts/documentation/_search.html.haml +5 -0
  32. data/app/views/layouts/documentation/application.html.haml +18 -0
  33. data/config/locales/en.yml +56 -0
  34. data/config/routes.rb +10 -0
  35. data/db/migrate/20140711185212_create_documentation_pages.rb +10 -0
  36. data/db/seeds.rb +15 -0
  37. data/lib/documentation.rb +16 -0
  38. data/lib/documentation/authorizer.rb +52 -0
  39. data/lib/documentation/config.rb +31 -0
  40. data/lib/documentation/engine.rb +29 -0
  41. data/lib/documentation/errors.rb +7 -0
  42. data/lib/documentation/generators/setup_generator.rb +13 -0
  43. data/lib/documentation/markdown_renderer.rb +62 -0
  44. data/lib/documentation/search_result.rb +84 -0
  45. data/lib/documentation/searchers/abstract.rb +47 -0
  46. data/lib/documentation/searchers/simple.rb +40 -0
  47. data/lib/documentation/version.rb +1 -1
  48. data/lib/documentation/view_helpers.rb +113 -0
  49. data/lib/tasks/documentation.rake +6 -0
  50. metadata +219 -3
@@ -0,0 +1,84 @@
1
+ module Documentation
2
+ class SearchResult
3
+
4
+ attr_accessor :query
5
+ attr_accessor :time
6
+ attr_accessor :raw_results
7
+ attr_accessor :results
8
+ attr_accessor :page
9
+ attr_accessor :per_page
10
+ attr_accessor :total_results
11
+
12
+ def initialize
13
+ @time = nil
14
+ @raw_results = {}
15
+ @page = 1
16
+ @total_pages = 1
17
+ @per_page = nil
18
+ end
19
+
20
+ #
21
+ # Return the pages
22
+ #
23
+ def results
24
+ @results ||= begin
25
+ results = Documentation::Page.where(:id => raw_results.keys).includes(:parent).to_a
26
+ results.sort_by { |p| raw_results.keys.index(p.id) }
27
+ end
28
+ end
29
+
30
+ #
31
+ # Return the highlight string for a given page
32
+ #
33
+ def excerpt_for(page)
34
+ if @raw_results[page.id] && hl = @raw_results[page.id][:highlights]
35
+ ERB::Util.html_escape((hl.join("..."))).gsub('{{{', "<mark>").gsub("}}}", "</mark>").html_safe
36
+ else
37
+ page.content[0,255].gsub(/[\n\r]/, '') + "..."
38
+ end
39
+ end
40
+
41
+ #
42
+ # Is the result set empty?
43
+ #
44
+ def empty?
45
+ self.results.empty?
46
+ end
47
+
48
+ #
49
+ # The total number of pages in the result set
50
+ #
51
+ def total_pages
52
+ (total_results / per_page.to_f).ceil
53
+ end
54
+
55
+ #
56
+ # The number of the first result on the current page
57
+ #
58
+ def start_result_number
59
+ ((page - 1) * per_page) + 1
60
+ end
61
+
62
+ #
63
+ # The number of the last result on the current page
64
+ #
65
+ def end_result_number
66
+ start_result_number + (results.size) - 1
67
+ end
68
+
69
+ #
70
+ # Is this the first page of the result set?
71
+ #
72
+ def first_page?
73
+ page == 1
74
+ end
75
+
76
+ #
77
+ # Is this the last page of the result set?
78
+ #
79
+ def last_page?
80
+ page == total_pages
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,47 @@
1
+ module Documentation
2
+ module Searchers
3
+ class Abstract
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ setup
10
+ end
11
+
12
+ #
13
+ # Run whatever initial set up is needed
14
+ #
15
+ def setup
16
+ end
17
+
18
+ #
19
+ # Search for a page from the index
20
+ #
21
+ def search(query, options = {})
22
+ []
23
+ end
24
+
25
+ #
26
+ # Delete a page from the index
27
+ #
28
+ def delete(page)
29
+ false
30
+ end
31
+
32
+ #
33
+ # Reset an index to have no data within it
34
+ #
35
+ def reset
36
+ true
37
+ end
38
+
39
+ #
40
+ # Add or update an page in the index
41
+ #
42
+ def index(page)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ module Documentation
2
+ module Searchers
3
+ class Simple < Documentation::Searchers::Abstract
4
+
5
+ def search(query, options = {})
6
+ # Default options
7
+ options[:page] ||= 1
8
+ options[:per_page] ||= 15
9
+
10
+ # Query string
11
+ query_string = "content LIKE ? OR title LIKE ?", "%#{query}%", "%#{query}"
12
+
13
+ # Get the total number of pages
14
+ total_results = pages = Documentation::Page.where(query_string).count
15
+
16
+ # Get the actual pages
17
+ pages = Documentation::Page.where(query_string)
18
+ pages = pages.offset((options[:page].to_i - 1) * options[:per_page].to_i)
19
+ pages = pages.limit(options[:per_page].to_i)
20
+
21
+ # Create a result object
22
+ result = Documentation::SearchResult.new
23
+ result.page = options[:page].to_i
24
+ result.per_page = options[:per_page].to_i
25
+ result.total_results = total_results
26
+ result.query = query
27
+ result.time = 0
28
+ result.results = pages
29
+
30
+ # Return the result
31
+ result
32
+ end
33
+
34
+ def index(page)
35
+ true
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Documentation
2
- VERSION = '0.0.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,113 @@
1
+ module Documentation
2
+ module ViewHelpers
3
+
4
+ #
5
+ # Path to edit a page in the manager UI
6
+ #
7
+ def documentation_edit_page_path(page)
8
+ "#{::Documentation::Engine.mounted_path}/edit/#{page.full_permalink}"
9
+ end
10
+
11
+ #
12
+ # Path to view a page in the manager UI
13
+ #
14
+ def documentation_page_path(page)
15
+ "#{::Documentation::Engine.mounted_path}/#{page.try(:full_permalink)}"
16
+ end
17
+
18
+ #
19
+ # Return a breadcrumb for the given page
20
+ #
21
+ def documentation_breadcrumb_for(page, options = {})
22
+ options[:root_link] = options[:root_link].nil? ? t('documentation.helpers.documentation_breadcrumb_for.default_root_link') : options[:root_link]
23
+ options[:class] ||= 'breadcrumb'
24
+
25
+ String.new.tap do |s|
26
+ s << "<nav class='#{options[:class]}'><ul>"
27
+
28
+ if options[:root_link]
29
+ s << "<li><a href='#{documentation_doc_root}'>#{options[:root_link]}</a></li>"
30
+ end
31
+
32
+ if page.is_a?(::Documentation::Page)
33
+ page.breadcrumb.each do |child|
34
+ s << "<li><a href='#{documentation_doc_root}/#{child.full_permalink}'>#{child.title}</a></li>"
35
+ end
36
+ end
37
+
38
+ s << "</ul></nav>"
39
+ end.html_safe
40
+ end
41
+
42
+ #
43
+ # Return a default navigation tree for the given page
44
+ #
45
+ def documentation_navigation_tree_for(page)
46
+ String.new.tap do |s|
47
+ s << "<ul>"
48
+ if page.is_a?(::Documentation::Page)
49
+ page.navigation.select { |p,c| documentation_authorizer.can_view_page?(p) }.each do |p, children|
50
+ s << "<li>"
51
+ s << "<a #{page == p ? "class='active'" : ''} href='#{documentation_doc_root}/#{p.full_permalink}'>#{p.title}</a>"
52
+ unless children.empty?
53
+ s << "<ul>"
54
+ children.select { |c| documentation_authorizer.can_view_page?(c) }.each do |p|
55
+ s << "<li><a #{page == p ? "class='active'" : ''} href='#{documentation_doc_root}/#{p.full_permalink}'>#{p.title}</a></li>"
56
+ end
57
+ s << "</ul>"
58
+ end
59
+ s << "</li>"
60
+ end
61
+ else
62
+ ::Documentation::Page.roots.each do |page|
63
+ s << "<li><a href='#{documentation_doc_root}/#{page.full_permalink}'>#{page.title}</a></li>"
64
+ end
65
+ end
66
+ s << "</ul>"
67
+ end.html_safe
68
+ end
69
+
70
+ #
71
+ # Return appropriate content for a given page
72
+ #
73
+ def documentation_content_for(page)
74
+ # Get the content
75
+ content = page.compiled_content.to_s
76
+
77
+ # Insert navigation
78
+ content.gsub!("<p class=''>{{nav}}</p>") do
79
+ children = page.children
80
+ children = children.select { |c| documentation_authorizer.can_view_page?(c) }
81
+ items = children.map { |c| "<li><a href='#{documentation_doc_root}/#{c.full_permalink}'>#{c.title}</a></li>" }.join
82
+ "<ul class='pages'>#{items}</ul>"
83
+ end
84
+
85
+ # Set the document root as appropriate
86
+ content.gsub!("{{docRoot}}", documentation_doc_root)
87
+
88
+ # Return HTML safe content
89
+ content.html_safe
90
+ end
91
+
92
+ #
93
+ # Return the documentation document root
94
+ #
95
+ def documentation_doc_root
96
+ @documentation_doc_root ||= begin
97
+ if controller.is_a?(Documentation::ApplicationController)
98
+ ::Documentation::Engine.mounted_path.to_s
99
+ else
100
+ ::Documentation.config.preview_path_prefix.to_s.sub(/\/$/, '')
101
+ end
102
+ end
103
+ end
104
+
105
+ #
106
+ # Return the documentation authorizer
107
+ #
108
+ def documentation_authorizer
109
+ @documentation_authorizer ||= Documentation.config.authorizer.new(controller)
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,6 @@
1
+ namespace :documentation do
2
+ desc "Load a set of initial guides"
3
+ task :install_guides => :environment do
4
+ require File.expand_path('../../../db/seeds', __FILE__)
5
+ end
6
+ end
metadata CHANGED
@@ -1,15 +1,185 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: haml
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: dynamic_form
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.1.4
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1.1'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.1.4
67
+ - !ruby/object:Gem::Dependency
68
+ name: jquery-rails
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '3'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3'
81
+ - !ruby/object:Gem::Dependency
82
+ name: coffee-rails
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '4'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '4'
95
+ - !ruby/object:Gem::Dependency
96
+ name: sass-rails
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '4.0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '4.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: uglifier
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '2.2'
116
+ - - "<"
117
+ - !ruby/object:Gem::Version
118
+ version: '3.0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '2.2'
126
+ - - "<"
127
+ - !ruby/object:Gem::Version
128
+ version: '3.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: redcarpet
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 3.1.0
136
+ - - "<"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.0'
139
+ type: :runtime
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 3.1.0
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: '4.0'
149
+ - !ruby/object:Gem::Dependency
150
+ name: pygments.rb
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0.5'
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.0'
159
+ type: :runtime
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0.5'
166
+ - - "<"
167
+ - !ruby/object:Gem::Version
168
+ version: '1.0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: sqlite3
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - "~>"
174
+ - !ruby/object:Gem::Version
175
+ version: '1.3'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - "~>"
181
+ - !ruby/object:Gem::Version
182
+ version: '1.3'
13
183
  description: It does cool stuff!
14
184
  email:
15
185
  - adam@atechmedia.com
@@ -17,8 +187,54 @@ executables: []
17
187
  extensions: []
18
188
  extra_rdoc_files: []
19
189
  files:
190
+ - app/assets/images/documentation/link.svg
191
+ - app/assets/images/documentation/logo-black.svg
192
+ - app/assets/images/documentation/logo-white.svg
193
+ - app/assets/images/documentation/page.svg
194
+ - app/assets/images/documentation/pin.svg
195
+ - app/assets/images/documentation/recommendation.svg
196
+ - app/assets/images/documentation/search.svg
197
+ - app/assets/images/documentation/unhappy.svg
198
+ - app/assets/images/documentation/warning.svg
199
+ - app/assets/javascripts/documentation/application.coffee
200
+ - app/assets/javascripts/documentation/jquery-ui.js
201
+ - app/assets/javascripts/documentation/jquery.autosize.js
202
+ - app/assets/stylesheets/documentation/application.scss
203
+ - app/assets/stylesheets/documentation/markdown.scss
204
+ - app/assets/stylesheets/documentation/page_form.scss
205
+ - app/assets/stylesheets/documentation/reset.scss
206
+ - app/controllers/documentation/application_controller.rb
207
+ - app/controllers/documentation/pages_controller.rb
208
+ - app/helpers/documentation/application_helper.rb
209
+ - app/models/documentation/page.rb
210
+ - app/views/documentation/pages/_admin_buttons.html.haml
211
+ - app/views/documentation/pages/form.html.haml
212
+ - app/views/documentation/pages/index.html.haml
213
+ - app/views/documentation/pages/positioning.html.haml
214
+ - app/views/documentation/pages/search.html.haml
215
+ - app/views/documentation/pages/show.html.haml
216
+ - app/views/documentation/shared/access_denied.html.haml
217
+ - app/views/documentation/shared/not_found.html.haml
218
+ - app/views/layouts/documentation/_header.html.haml
219
+ - app/views/layouts/documentation/_search.html.haml
220
+ - app/views/layouts/documentation/application.html.haml
221
+ - config/locales/en.yml
222
+ - config/routes.rb
223
+ - db/migrate/20140711185212_create_documentation_pages.rb
224
+ - db/seeds.rb
20
225
  - lib/documentation.rb
226
+ - lib/documentation/authorizer.rb
227
+ - lib/documentation/config.rb
228
+ - lib/documentation/engine.rb
229
+ - lib/documentation/errors.rb
230
+ - lib/documentation/generators/setup_generator.rb
231
+ - lib/documentation/markdown_renderer.rb
232
+ - lib/documentation/search_result.rb
233
+ - lib/documentation/searchers/abstract.rb
234
+ - lib/documentation/searchers/simple.rb
21
235
  - lib/documentation/version.rb
236
+ - lib/documentation/view_helpers.rb
237
+ - lib/tasks/documentation.rake
22
238
  homepage: http://adamcooke.io
23
239
  licenses:
24
240
  - MIT