static_docs 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +178 -2
- data/app/controllers/static_docs/pages_controller.rb +1 -1
- data/app/models/static_docs/page.rb +2 -1
- data/config/routes.rb +1 -1
- data/lib/static_docs/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +2469 -0
- data/test/dummy/sources/namespace/{home.html → index.html} +0 -0
- data/test/dummy/sources/namespace/index.yml +2 -2
- data/test/dummy/sources/root/{home.html → index.html} +0 -0
- data/test/dummy/sources/root/index.yml +2 -2
- data/test/fixtures/static_docs/pages.yml +8 -1
- data/test/unit/static_docs/importer_test.rb +2 -2
- data/test/unit/static_docs/page_test.rb +8 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -1,6 +1,182 @@
|
|
1
1
|
StaticDocs
|
2
2
|
==========
|
3
3
|
|
4
|
-
StaticDocs is about some static pages. These static pages can be created, stored
|
4
|
+
StaticDocs is about some static pages. These static pages can be created, stored
|
5
|
+
and edited as files. Then they can be imported into DB of your app and be shown
|
6
|
+
within app's layout. Rules of displaying are described in special manifest file,
|
7
|
+
gem's initializer of app and in route file.
|
5
8
|
|
6
|
-
|
9
|
+
This gem was extracted from [Rusrails](http://rusrails.ru), so you can use its
|
10
|
+
[source code](https://github.com/morsbox/rusrails) as demo example.
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
StaticDocs is Rails engine, it works with Rails 3.1+.
|
16
|
+
|
17
|
+
Add in Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'static_docs'
|
21
|
+
```
|
22
|
+
|
23
|
+
Then copy migrations `rake static_docs:install:migrations` and run them
|
24
|
+
`rake db:migrate`.
|
25
|
+
|
26
|
+
Then mount its engine at the bottom of your `config/routes.rb` (because it is
|
27
|
+
greedy and following routes will never be mapped)
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
mount StaticDocs::Engine => "/"
|
31
|
+
```
|
32
|
+
|
33
|
+
Then create initializer in `config/initializers/static_docs.rb`
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# Probably you also want this shortcut for static_docs pages:
|
37
|
+
# Page = StaticDocs::Page
|
38
|
+
|
39
|
+
StaticDocs.setup do
|
40
|
+
source 'source'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Then create your source manifest in `source/index.yml`
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
special:
|
48
|
+
- title: Main Page
|
49
|
+
path: index
|
50
|
+
file: index.html
|
51
|
+
|
52
|
+
pages:
|
53
|
+
- title: This is Just Page
|
54
|
+
path: page
|
55
|
+
file: page.html
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
Then create listed docs `source/index.html` and `source/page.html` with content
|
60
|
+
you want.
|
61
|
+
|
62
|
+
And next run `rake static_docs:import` to import files into database. You should
|
63
|
+
run this task after each change of source files.
|
64
|
+
|
65
|
+
Thats it! Follow to `/` or `/page` and you will see your pages within
|
66
|
+
application layout!
|
67
|
+
|
68
|
+
Using
|
69
|
+
-----
|
70
|
+
|
71
|
+
### Routes
|
72
|
+
|
73
|
+
This is mountable engine and it should be mounted in your routes file
|
74
|
+
(`config/routes.rb`).
|
75
|
+
|
76
|
+
Because it routes all requests within mounted path to own controller, you should
|
77
|
+
mount at bottom of routes file (especially if you mount on `'/'` path).
|
78
|
+
|
79
|
+
### Sources
|
80
|
+
|
81
|
+
You can describe several sources in initializer.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
StaticDocs.setup do
|
85
|
+
# Root namespace have source in 'sources/root' of your Rails app
|
86
|
+
source 'sources/root'
|
87
|
+
|
88
|
+
# Faq namespace have source in 'sources/faq' of your Rails app. These pages
|
89
|
+
# will be available at `/faq/page_path`
|
90
|
+
source 'sources/faq', :namespace => :faq
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
### Renderers
|
95
|
+
|
96
|
+
Extension of each source defines which renderer should be used. For example, for
|
97
|
+
`page.html` will be used `html` renderer, but for `faq.md` will be used `md`
|
98
|
+
renderer. By default there are only `html` and `txt` renderers:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
:html => proc{ |body| body.html_safe },
|
102
|
+
:txt => proc{ |body| body }
|
103
|
+
```
|
104
|
+
|
105
|
+
You can define own renderers in initializer.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
StaticDocs.setup do
|
109
|
+
source 'source'
|
110
|
+
|
111
|
+
# Renderer is evaluated in view context. `markdown` method can be defined
|
112
|
+
# somewhere in view helpers
|
113
|
+
renderer :md do |body|
|
114
|
+
markdown(body)
|
115
|
+
end
|
116
|
+
|
117
|
+
# You can redefine default renderer (`txt`), and also have access to page
|
118
|
+
# instance. Page have `meta` hash, that special exists for using inside
|
119
|
+
# renderer to pass some data outside.
|
120
|
+
renderer :txt do |body, page|
|
121
|
+
page.meta[:test] = 'test'
|
122
|
+
page.meta[:test] * 3
|
123
|
+
end
|
124
|
+
|
125
|
+
# You can also define renderer for specific namespace
|
126
|
+
renderer :md, :namespace => :examples do |body|
|
127
|
+
"<pre>#{body}</pre>".html_safe
|
128
|
+
end
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
### Views
|
133
|
+
|
134
|
+
If you dissatisfied default view you can create own in
|
135
|
+
`app/views/static_docs/pages/show.html.erb`.
|
136
|
+
|
137
|
+
Page is avalable as `@page` instance variable. Use `@page.rendered_body(self)`
|
138
|
+
to get rendered body.
|
139
|
+
|
140
|
+
### Import
|
141
|
+
|
142
|
+
Task for import pages to database is `rake static_pages:import`. Use
|
143
|
+
`namespace=xxx` or `namespaces=xxx,yyy` to point what namespace to import. Use
|
144
|
+
keyword `root` to point on root namespace.
|
145
|
+
|
146
|
+
### Deploy
|
147
|
+
|
148
|
+
There is not special capistrano task for importing on deploy. Compose own task
|
149
|
+
that invokes `static_pages:import` rake task.
|
150
|
+
|
151
|
+
TODO list
|
152
|
+
---------
|
153
|
+
|
154
|
+
- setup generator
|
155
|
+
- new doc generator
|
156
|
+
- capistrano task
|
157
|
+
- travis-ci
|
158
|
+
- more ways where to store docs (another repo / web / absolute path)
|
159
|
+
- skipping index page
|
160
|
+
- more verbose error handling and warnings
|
161
|
+
- custom fields for pages
|
162
|
+
- url helper for page (it should take in count where engine is mounted + namespace + path)
|
163
|
+
|
164
|
+
Note on Patches/Pull Requests
|
165
|
+
-----------------------------
|
166
|
+
|
167
|
+
- Fork the project.
|
168
|
+
- Make your feature addition or bug fix.
|
169
|
+
- Add tests for it. This is important so I don't break it in a future version unintentionally.
|
170
|
+
- Commit, do not mess with rakefile, version, or history.
|
171
|
+
- Send me a pull request. Bonus points for topic branches.
|
172
|
+
|
173
|
+
The MIT License (MIT)
|
174
|
+
---------------------
|
175
|
+
|
176
|
+
Copyright 2013 Mikhail Dieterle (Mik-die)
|
177
|
+
|
178
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
179
|
+
|
180
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
181
|
+
|
182
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -9,7 +9,8 @@ module StaticDocs
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def namespaced_matched(path, namespace = nil)
|
12
|
-
if
|
12
|
+
if StaticDocs.namespaces.include?(namespace)
|
13
|
+
path = 'index' unless path.present?
|
13
14
|
where(:namespace => namespace, :path => path).first
|
14
15
|
end
|
15
16
|
end
|
data/config/routes.rb
CHANGED
data/lib/static_docs/version.rb
CHANGED
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|