faqmarkdown 0.0.1
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 +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Appraisals +13 -0
- data/Gemfile +10 -0
- data/Rakefile +11 -0
- data/app/controllers/application_controller.rb +2 -0
- data/app/controllers/faqs_controller.rb +66 -0
- data/app/helpers/faq_helper.rb +23 -0
- data/app/models/faq.rb +170 -0
- data/app/views/faqs/_faq.html.haml +16 -0
- data/app/views/faqs/_feed_link.html.haml +2 -0
- data/app/views/faqs/feed.xml.builder +29 -0
- data/app/views/faqs/index.html.haml +8 -0
- data/app/views/faqs/show.html.haml +3 -0
- data/app/views/layouts/faqmarkdown.html.haml +16 -0
- data/config.ru +8 -0
- data/faqmarkdown.gemspec +37 -0
- data/gemfiles/rails3_0.gemfile +13 -0
- data/gemfiles/rails3_1.gemfile +14 -0
- data/gemfiles/rails3_2.gemfile +14 -0
- data/lib/faqmarkdown/config.rb +24 -0
- data/lib/faqmarkdown/engine.rb +12 -0
- data/lib/faqmarkdown/railtie.rb +20 -0
- data/lib/faqmarkdown/routes.rb +30 -0
- data/lib/faqmarkdown/util.rb +12 -0
- data/lib/faqmarkdown/version.rb +3 -0
- data/lib/faqmarkdown.rb +5 -0
- data/lib/generators/faqmarkdown/faq_generator.rb +42 -0
- data/lib/generators/faqmarkdown/install_generator.rb +19 -0
- data/lib/generators/faqmarkdown/override_generator.rb +48 -0
- data/lib/generators/faqmarkdown/templates/example-faq.markdown +67 -0
- data/lib/generators/faqmarkdown/usage/faq.txt +14 -0
- data/lib/generators/faqmarkdown/usage/install.txt +10 -0
- data/lib/generators/faqmarkdown/usage/override.txt +9 -0
- data/readme.md +191 -0
- data/spec/helpers/faq_helper_spec.rb +49 -0
- data/spec/integrations/faqs_spec.rb +209 -0
- data/spec/internal/.gitignore +2 -0
- data/spec/internal/app/faqs/2011-04-01-first-faq.markdown +5 -0
- data/spec/internal/app/faqs/2011-04-28-image.markdown +5 -0
- data/spec/internal/app/faqs/2011-04-28-summary.markdown +10 -0
- data/spec/internal/app/faqs/2011-05-01-full-metadata.markdown +20 -0
- data/spec/internal/app/faqs/2015-02-13-custom-title.markdown +5 -0
- data/spec/internal/app/views/layouts/application.html.erb +12 -0
- data/spec/internal/app/views/layouts/custom_layout.html.erb +14 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/environments/test.rb +9 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/generators/faqmarkdown/faq_generator_spec.rb +99 -0
- data/spec/models/faqs_spec.rb +103 -0
- data/spec/requests/assets_spec.rb +16 -0
- data/spec/requests/views_spec.rb +34 -0
- data/spec/routing/faqs_routing_spec.rb +80 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/data/faqs/2011-04-01-first-faq.markdown +3 -0
- data/spec/support/data/faqs/2011-04-28-image.markdown +9 -0
- data/spec/support/data/faqs/2011-04-28-summary.markdown +10 -0
- data/spec/support/data/faqs/2011-05-01-full-metadata.markdown +13 -0
- data/spec/support/data/faqs/2011-05-02-md-file-extension.md +1 -0
- data/spec/support/data/faqs/2011-05-02-mdown-file-extension.mdown +1 -0
- data/spec/support/data/faqs/2011-05-02-mkd-file-extension.mkd +1 -0
- data/spec/support/data/faqs/2012-02-13-102030-custom-title-and-timestamp.markdown +5 -0
- data/spec/support/data/faqs/2015-02-13-custom-title.markdown +5 -0
- data/spec/support/data/faqs/missing-date-from-filename.markdown +1 -0
- data/spec/support/rails_app/.gitignore +4 -0
- data/spec/support/rails_app/app/controllers/application_controller.rb +3 -0
- data/spec/support/rails_app/app/faqs/2011-04-01-first-faq.markdown +5 -0
- data/spec/support/rails_app/app/faqs/2011-04-28-image.markdown +5 -0
- data/spec/support/rails_app/app/faqs/2011-04-28-summary.markdown +10 -0
- data/spec/support/rails_app/app/faqs/2011-05-01-full-metadata.markdown +20 -0
- data/spec/support/rails_app/app/faqs/2015-02-13-custom-title.markdown +5 -0
- data/spec/support/rails_app/app/views/layouts/application.html.erb +12 -0
- data/spec/support/rails_app/app/views/layouts/custom_layout.html.erb +14 -0
- data/spec/support/rails_app/config/application.rb +42 -0
- data/spec/support/rails_app/config/boot.rb +10 -0
- data/spec/support/rails_app/config/database.yml +22 -0
- data/spec/support/rails_app/config/environment.rb +5 -0
- data/spec/support/rails_app/config/environments/test.rb +9 -0
- data/spec/support/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/support/rails_app/config/routes.rb +3 -0
- data/spec/support/rails_app/config.ru +4 -0
- data/spec/support/rails_app/db/seeds.rb +7 -0
- data/spec/support/rails_app/doc/README_FOR_APP +2 -0
- data/vendor/assets/stylesheets/faqmarkdown/faqmarkdown.css +69 -0
- metadata +354 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Faqmarkdown
|
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
|
3
|
+
desc File.read(File.expand_path('../usage/install.txt', __FILE__)).gsub('{{CURRENT_DATE}}', Time.zone.now.strftime('%Y-%m-%d'))
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
class_option :skip_example, :type => :boolean, :group => :runtime, :desc => 'Skip generating an example faq'
|
|
6
|
+
|
|
7
|
+
def create_directory
|
|
8
|
+
empty_directory 'app/faqs'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def generate_example_faq
|
|
12
|
+
generate 'faqmarkdown:faq', 'example-faq' unless options.skip_example?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_routes
|
|
16
|
+
insert_into_file 'config/routes.rb', " faqmarkdown :as => :faqs\n\n", :after => "::Application.routes.draw do\n"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Faqmarkdown
|
|
2
|
+
class OverrideGenerator < Rails::Generators::Base
|
|
3
|
+
desc File.read(File.expand_path('../usage/override.txt', __FILE__))
|
|
4
|
+
source_root File.expand_path('../../../../app', __FILE__)
|
|
5
|
+
|
|
6
|
+
class_option :all, :type => :boolean, :group => :override, :desc => 'Override all of the things'
|
|
7
|
+
class_option :views, :type => :boolean, :group => :override, :desc => 'Override the Faq views'
|
|
8
|
+
class_option :model, :type => :boolean, :group => :override, :desc => 'Override the Faq model'
|
|
9
|
+
class_option :controller, :type => :boolean, :group => :override, :desc => 'Override the Faqs controller'
|
|
10
|
+
class_option :theme, :type => :boolean, :group => :override, :desc => 'Override the layout and stylesheet'
|
|
11
|
+
|
|
12
|
+
def check_class_options
|
|
13
|
+
if options.blank?
|
|
14
|
+
exec 'rails g faqmarkdown:override --help'
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def override_views
|
|
20
|
+
if options.views || options.all
|
|
21
|
+
directory 'views/faqs', 'app/views/faqs'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def override_model
|
|
26
|
+
if options.model || options.all
|
|
27
|
+
copy_file 'models/faq.rb', 'app/models/faq.rb'
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def override_controller
|
|
32
|
+
if options.controller || options.all
|
|
33
|
+
copy_file 'controllers/faqs_controller.rb', 'app/controllers/faqs_controller.rb'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def override_theme
|
|
38
|
+
if options.theme || options.all
|
|
39
|
+
directory 'views/layouts', 'app/views/layouts'
|
|
40
|
+
if Rails.application.config.respond_to?(:assets) && Rails.application.config.assets.enabled
|
|
41
|
+
directory '../vendor/assets/stylesheets', 'app/assets/stylesheets'
|
|
42
|
+
else
|
|
43
|
+
directory '../vendor/assets/stylesheets', 'public/stylesheets'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: <%= slug.gsub('-',' ').capitalize %>
|
|
3
|
+
<%- if author = Faqmarkdown::Util.git_config('user.name') -%>
|
|
4
|
+
author: <%= author %>
|
|
5
|
+
<%- end -%>
|
|
6
|
+
<%- if email = Faqmarkdown::Util.git_config('user.email') -%>
|
|
7
|
+
email: <%= email %>
|
|
8
|
+
<%- end -%>
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
12
|
+
|
|
13
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
14
|
+
|
|
15
|
+
# Markdown Formatting
|
|
16
|
+
|
|
17
|
+
[Reference](http://daringfireball.net/projects/markdown/syntax)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Headers
|
|
22
|
+
|
|
23
|
+
## Header 2
|
|
24
|
+
|
|
25
|
+
### Header 3
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
# Emphasis
|
|
30
|
+
|
|
31
|
+
*italic* **bold**
|
|
32
|
+
_italic_ __bold__
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
# Links and Images
|
|
37
|
+
|
|
38
|
+
An [example](http://url.com/ "Title") Reference-style labels (titles are optional):
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
# Lists
|
|
45
|
+
|
|
46
|
+
1. Foo
|
|
47
|
+
2. Bar
|
|
48
|
+
|
|
49
|
+
Unordered, with nesting:
|
|
50
|
+
|
|
51
|
+
* Abacus
|
|
52
|
+
* answer
|
|
53
|
+
* Bubbles
|
|
54
|
+
1. bunk
|
|
55
|
+
2. bupkis
|
|
56
|
+
* BELITTLER
|
|
57
|
+
3. burper
|
|
58
|
+
* Cunning
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
# Preformatted Code Blocks
|
|
63
|
+
|
|
64
|
+
Indent every line of a code block by at least 4 spaces or 1 tab.
|
|
65
|
+
|
|
66
|
+
This is a preformatted
|
|
67
|
+
code block.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
This generator will produce a new faq by creating a markdown file in the `app/faqs/` directory. The filename for the new file will be generated using the slug and publish date specified.
|
|
3
|
+
|
|
4
|
+
Example 1:
|
|
5
|
+
$ rails generate faqmarkdown:faq example-1
|
|
6
|
+
|
|
7
|
+
This will:
|
|
8
|
+
- Generate a new faq using the slug specified and today's date: `app/faqs/{{CURRENT_DATE}}-example-1.markdown`.
|
|
9
|
+
|
|
10
|
+
Example 2:
|
|
11
|
+
$ rails generate faqmarkdown:faq example-2 --date=2012-04-10
|
|
12
|
+
|
|
13
|
+
This will:
|
|
14
|
+
- Generate a new faq using the slug and publish date specified: `app/posts/2012-04-10-example-2.markdown`.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
This generator will create the directory structure and routes required by Faqmarkdown. As an added bonus, it will create an example Faq for the current date.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
$ rails generate faqmarkdown:install
|
|
6
|
+
|
|
7
|
+
This will:
|
|
8
|
+
- Create the directory `app/faqs/`.
|
|
9
|
+
- Generate an example Faq using today's date: `app/faqs/{{CURRENT_DATE}}-example-faq.markdown`.
|
|
10
|
+
- Add default routes.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
This generator will override either the Faq model, controller or views.
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
$ rails generate faqmarkdown:override --all # overrides all of the things
|
|
6
|
+
$ rails generate faqmarkdown:override --controller # overrides file `app/controllers/faqs_controller.rb`
|
|
7
|
+
$ rails generate faqmarkdown:override --model # overrides file `app/models/faq.rb`
|
|
8
|
+
$ rails generate faqmarkdown:override --views # overrides all files in directory `app/views/faqs/`
|
|
9
|
+
$ rails generate faqmarkdown:override --theme # overrides the layout and stylesheet
|
data/readme.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Faqmarkdown
|
|
2
|
+
|
|
3
|
+
A simple Rails FAQ engine powered by Markdown.
|
|
4
|
+
|
|
5
|
+
Faqmarkdown is compatible with Rails 3 only and the gem is hosted on [RubyGems.org](http://rubygems.org/gems/faqmarkdown).
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* Markdown files for faq
|
|
10
|
+
* No database
|
|
11
|
+
* RSS Feed
|
|
12
|
+
* Customizable Routes
|
|
13
|
+
* Built-in minimal theme (optional)
|
|
14
|
+
* HTML5
|
|
15
|
+
* Rails engine (so you can override models, views, controllers, etc)
|
|
16
|
+
* Easily customized
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Simply add Faqmarkdown to your Gemfile and bundle it up:
|
|
21
|
+
|
|
22
|
+
gem 'faqmarkdown'
|
|
23
|
+
|
|
24
|
+
Then, run the generator to setup Faqmarkdown for your application:
|
|
25
|
+
|
|
26
|
+
$ rails generate faqmarkdown:install
|
|
27
|
+
|
|
28
|
+
The above command performs the following actions:
|
|
29
|
+
|
|
30
|
+
* Create the directory `app/faqs/`. This directory is where your markdown files will live.
|
|
31
|
+
* Generate an example faq using today's date, eg. `app/faqs/2011-01-01-example-faq.markdown`.
|
|
32
|
+
* Add some routes. By default the routes are setup underneath the path `/faqs/*`, to customize these routes check out the Customizing Routes section below.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Generate a new Faq
|
|
37
|
+
|
|
38
|
+
Here's an example of how to generate a new faq using a slug and publish date:
|
|
39
|
+
|
|
40
|
+
$ rails generate faqmarkdown:faq test-faq --date=2011-01-01
|
|
41
|
+
|
|
42
|
+
The above command will create the file `app/faqs/2011-01-01-test-faq.markdown`, which you can edit and add content to.
|
|
43
|
+
|
|
44
|
+
### Creating a brief summary
|
|
45
|
+
|
|
46
|
+
In their markdown, place the tag below, and everything above it will appear at the summary of your faq.
|
|
47
|
+
|
|
48
|
+
Tag:
|
|
49
|
+
|
|
50
|
+
<!--more-->
|
|
51
|
+
|
|
52
|
+
### Faq to categories
|
|
53
|
+
|
|
54
|
+
To put your faq in some categories, use:
|
|
55
|
+
|
|
56
|
+
categories:
|
|
57
|
+
- foo
|
|
58
|
+
- bar
|
|
59
|
+
|
|
60
|
+
This is an Array of their categories in the faq.
|
|
61
|
+
|
|
62
|
+
To list all categories, use:
|
|
63
|
+
|
|
64
|
+
faq.categories_all
|
|
65
|
+
|
|
66
|
+
This will return:
|
|
67
|
+
|
|
68
|
+
["foo", "bar"]
|
|
69
|
+
|
|
70
|
+
To do a search for a particular category, do:
|
|
71
|
+
|
|
72
|
+
faq.find_by_category ('foo')
|
|
73
|
+
|
|
74
|
+
This will return your faqs that have a category named `foo`.
|
|
75
|
+
|
|
76
|
+
### View the faq
|
|
77
|
+
|
|
78
|
+
Open `http://localhost:3000/faqs` in your browser and you should be able to navigate to your new faq. The URL for your new faq is `http://localhost:3000/faqs/2011/01/01/test-faq`.
|
|
79
|
+
|
|
80
|
+
## Overriding Files
|
|
81
|
+
|
|
82
|
+
The easiest way to customize the Faqmarkdown functionality or appearance is by using the override generator. This generator can copy files from the Faqmarkdown core and place them into your Rails app. For example:
|
|
83
|
+
|
|
84
|
+
$ rails generate faqmarkdown:override --all # overrides all of the things
|
|
85
|
+
$ rails generate faqmarkdown:override --controller # overrides `app/controllers/faqs_controller.rb`
|
|
86
|
+
$ rails generate faqmarkdown:override --model # overrides `app/models/faq.rb`
|
|
87
|
+
$ rails generate faqmarkdown:override --views # overrides all files in directory `app/views/faqs/`
|
|
88
|
+
$ rails generate faqmarkdown:override --theme # overrides the layout and stylesheet
|
|
89
|
+
|
|
90
|
+
## RSS Feed
|
|
91
|
+
|
|
92
|
+
Faqmarkdown comes prepared with a fully functional RSS feed.
|
|
93
|
+
|
|
94
|
+
You can take advantage of the built-in feed by adding the feed link to your HTML head tag. For example, simply add the following to your default layout:
|
|
95
|
+
|
|
96
|
+
<head>
|
|
97
|
+
<!-- include your stylesheets and javascript here... -->
|
|
98
|
+
<%= yield :head %>
|
|
99
|
+
</head>
|
|
100
|
+
|
|
101
|
+
To customize the feed title, add the following to an initializer (`config/initializers/faqmarkdown.rb`):
|
|
102
|
+
|
|
103
|
+
Faqmarkdown::Config.options[:feed_title] = 'Custom Faq Title Goes Here'
|
|
104
|
+
|
|
105
|
+
To link to the feed in your app, simply use the route helper: `<%= link_to 'RSS Feed', faqs_feed_path %>`
|
|
106
|
+
|
|
107
|
+
## Customizing the layout
|
|
108
|
+
|
|
109
|
+
By default, Faqmarkdown will use your application's default layout, but if you wish to use a specific custom layout, you can set the following configuration in an initializer (`config/initializers/faqmarkdown.rb`):
|
|
110
|
+
|
|
111
|
+
Faqmarkdown::Config.options[:layout] = 'layout_name'
|
|
112
|
+
|
|
113
|
+
### Built-in Theme
|
|
114
|
+
|
|
115
|
+
Faqmarkdown comes with minimal built-in theme for your convenience.
|
|
116
|
+
|
|
117
|
+
Faqmarkdown::Config.options[:layout] = 'faqmarkdown'
|
|
118
|
+
|
|
119
|
+
## Customizing Routes
|
|
120
|
+
|
|
121
|
+
By default Faqmarkdown will setup all routes to go through the `/faqs/*` path. For example:
|
|
122
|
+
|
|
123
|
+
http://example.com/faqs # lists all faqs
|
|
124
|
+
http://example.com/faqs/2011 # lists all faqs from 2011
|
|
125
|
+
http://example.com/faqs/2011/01 # lists all faqs from January 2011
|
|
126
|
+
http://example.com/faqs/2011/01/01 # lists all faqs from the 1st of January 2011
|
|
127
|
+
http://example.com/faqs/2011/01/01/test-faq # show the specified faq
|
|
128
|
+
|
|
129
|
+
You can change the default route path by modifying the 'faqmarkdown' line in `routes.rb`. For example:
|
|
130
|
+
|
|
131
|
+
faqmarkdown :as => :faq
|
|
132
|
+
|
|
133
|
+
This will produce the following routes:
|
|
134
|
+
|
|
135
|
+
http://example.com/faq # lists all faqs
|
|
136
|
+
http://example.com/faq/2011 # lists all faqs from 2011
|
|
137
|
+
http://example.com/faq/2011/01 # lists all faqs from January 2011
|
|
138
|
+
http://example.com/faq/2011/01/01 # lists all faqs from the 1st of January 2011
|
|
139
|
+
http://example.com/faq/2011/01/01/test-faq # show the specified faq
|
|
140
|
+
|
|
141
|
+
You can also customize the `faqs#show` route via the `:permalink_format` option:
|
|
142
|
+
|
|
143
|
+
faqmarkdown :as => :faq, :permalink_format => :day # URL: http://example.com/faq/2011/01/01/test-faq
|
|
144
|
+
faqmarkdown :as => :faq, :permalink_format => :month # URL: http://example.com/faq/2011/01/test-faq
|
|
145
|
+
faqmarkdown :as => :faq, :permalink_format => :year # URL: http://example.com/faq/2011/test-faq
|
|
146
|
+
faqmarkdown :as => :faq, :permalink_format => :slug # URL: http://example.com/faq/test-faq
|
|
147
|
+
|
|
148
|
+
What about mapping Faqmarkdown to root? We got you covered:
|
|
149
|
+
|
|
150
|
+
faqmarkdown :as => ''
|
|
151
|
+
root :to => 'faqs#index'
|
|
152
|
+
|
|
153
|
+
## Example Directory Structure
|
|
154
|
+
|
|
155
|
+
├── app
|
|
156
|
+
│ ├── controllers
|
|
157
|
+
│ ├── helpers
|
|
158
|
+
│ ├── mailers
|
|
159
|
+
│ ├── models
|
|
160
|
+
│ ├── faqs (where your markdown files live)
|
|
161
|
+
│ │ ├── 2011-04-01-example-1.markdown
|
|
162
|
+
│ │ ├── 2011-04-02-example-2.markdown
|
|
163
|
+
│ │ ├── 2011-04-03-example-3.markdown
|
|
164
|
+
│ │ ├── 2011-04-04-example-4.markdown
|
|
165
|
+
│ └── views
|
|
166
|
+
│ └── faqs (overridable)
|
|
167
|
+
│ ├── _feed_link.html.haml
|
|
168
|
+
│ ├── _faq.html.haml
|
|
169
|
+
│ ├── feed.xml.builder
|
|
170
|
+
│ ├── index.html.haml
|
|
171
|
+
│ └── show.html.haml
|
|
172
|
+
|
|
173
|
+
## TODO
|
|
174
|
+
|
|
175
|
+
* Syntax highlighting for code blocks
|
|
176
|
+
* Generated routes should show example usage
|
|
177
|
+
* Support more file formats, eg. textile
|
|
178
|
+
* Built-in theme should have a link to the RSS Feed
|
|
179
|
+
* Generator tests
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
bundle
|
|
185
|
+
rake appraisal:install
|
|
186
|
+
rake # run the tests
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT License. Copyright 2011 Ennova.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe FaqHelper do
|
|
4
|
+
def test_faq(file_name)
|
|
5
|
+
Faq.new(File.dirname(__FILE__) + "/../support/data/faqs/#{file_name}")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:summary_html) { helper.faq_summary_html(faq) }
|
|
9
|
+
let(:content_html) { helper.faq_content_html(faq) }
|
|
10
|
+
|
|
11
|
+
context 'with first faq' do
|
|
12
|
+
let(:faq) { test_faq '2011-04-01-first-faq.markdown' }
|
|
13
|
+
|
|
14
|
+
it 'renders HTML content' do
|
|
15
|
+
content_html.should be_html_safe
|
|
16
|
+
content_html.should =~ /^<p>Lorem ipsum/
|
|
17
|
+
content_html.should =~ /^<p>Duis aute irure dolor/
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'renders HTML summary' do
|
|
21
|
+
summary_html.should be_html_safe
|
|
22
|
+
summary_html.should =~ /^<p>Lorem ipsum/
|
|
23
|
+
summary_html.should_not =~ /^<p>Duis aute irure dolor/
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'with image faq' do
|
|
28
|
+
let(:faq) { test_faq '2011-04-28-image.markdown' }
|
|
29
|
+
|
|
30
|
+
it 'renders HTML summary' do
|
|
31
|
+
summary_html.should be_html_safe
|
|
32
|
+
summary_html.should =~ /^<p><img src=\"example.png\">/
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'renders HTML content' do
|
|
36
|
+
content_html.should be_html_safe
|
|
37
|
+
content_html.should =~ /^<p><img src="example.png" \/>/
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'with custom summary faq' do
|
|
42
|
+
let(:faq) { test_faq '2011-04-28-summary.markdown' }
|
|
43
|
+
|
|
44
|
+
it 'renders HTML summary' do
|
|
45
|
+
summary_html.should be_html_safe
|
|
46
|
+
summary_html.should eq '<p>This is a custom & test summary.</p>'
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'Faq views', :type => :request do
|
|
4
|
+
before do
|
|
5
|
+
time_travel_to '2011-05-01'
|
|
6
|
+
Faq.reset!
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
after { back_to_the_present }
|
|
10
|
+
|
|
11
|
+
context 'Faqs#index' do
|
|
12
|
+
context 'default index' do
|
|
13
|
+
before { visit faqs_path }
|
|
14
|
+
|
|
15
|
+
it 'should show published faqs' do
|
|
16
|
+
# 2011-05-01-full-metadata (published today)
|
|
17
|
+
page.should have_content('Faq with full metadata') # title
|
|
18
|
+
page.should have_content('Posted on 1 May 2011') # publish date
|
|
19
|
+
page.should have_content('by John Smith') # author
|
|
20
|
+
page.should have_content('This is another custom & test summary.') # summary
|
|
21
|
+
|
|
22
|
+
# 2011-04-28-summary
|
|
23
|
+
page.should have_content('A Test Faq') # title
|
|
24
|
+
page.should have_content('Posted on 28 April 2011') # publish date
|
|
25
|
+
page.should have_content('This is a custom & test summary.') # summary
|
|
26
|
+
|
|
27
|
+
# 2011-04-28-image
|
|
28
|
+
page.should have_content('Image') # title
|
|
29
|
+
page.should have_content('Posted on 28 April 2011') # publish date
|
|
30
|
+
|
|
31
|
+
# 2011-04-01-first-post
|
|
32
|
+
page.should have_content('First Faq') # title
|
|
33
|
+
page.should have_content('Posted on 1 April 2011') # publish date
|
|
34
|
+
page.should have_content('Lorem ipsum dolor sit amet') # part of summary
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should not show unpublished faqs' do
|
|
38
|
+
# 2015-02-13-custom-title (not published yet)
|
|
39
|
+
page.should_not have_content('This is a custom title') # title
|
|
40
|
+
page.should_not have_content('Content goes here.') # summary
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'should have the correct number of faqs' do
|
|
44
|
+
all('section#faqs article.faq').size.should == 4
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'pagination' do
|
|
49
|
+
def article_titles
|
|
50
|
+
all('article header h1').map(&:text)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
before do
|
|
54
|
+
visit faqs_path(:count => 2)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'returns the latest faqs on the first page' do
|
|
58
|
+
article_titles.should eq [
|
|
59
|
+
'Faq with full metadata',
|
|
60
|
+
'A Test Faq',
|
|
61
|
+
]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns earlier faqs on the second page' do
|
|
65
|
+
click_link 'Next'
|
|
66
|
+
article_titles.should eq [
|
|
67
|
+
'Image',
|
|
68
|
+
'First Faq',
|
|
69
|
+
]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context 'Faqs#index with no faqs' do
|
|
75
|
+
it 'should show a message' do
|
|
76
|
+
time_travel_to '2010-05-01'
|
|
77
|
+
visit faqs_path
|
|
78
|
+
|
|
79
|
+
page.should have_content('No faqs found.')
|
|
80
|
+
page.should_not have_content('First Faq')
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'Faqs#index with year' do
|
|
85
|
+
before { visit faqs_path(:year => '2011') }
|
|
86
|
+
|
|
87
|
+
it 'should show faqs inside the date range' do
|
|
88
|
+
page.should have_content('Faq with full metadata')
|
|
89
|
+
page.should have_content('A Test Faq')
|
|
90
|
+
page.should have_content('Image')
|
|
91
|
+
page.should have_content('First Faq')
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context 'Faqs#index with year and month' do
|
|
96
|
+
before { visit faqs_path(:year => '2011', :month => '04') }
|
|
97
|
+
|
|
98
|
+
it 'should show faqs inside the date range' do
|
|
99
|
+
page.should have_content('A Test Faq')
|
|
100
|
+
page.should have_content('Image')
|
|
101
|
+
page.should have_content('First Faq')
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'should not show posts outside the date range' do
|
|
105
|
+
page.should_not have_content('Faq with full metadata')
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context 'Faqs#index with year, month and day' do
|
|
110
|
+
before { visit faqs_path(:year => '2011', :month => '04', :day => '01') }
|
|
111
|
+
|
|
112
|
+
it 'should show faqs inside the date range' do
|
|
113
|
+
page.should have_content('First Faq')
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'should not show faqs outside the date range' do
|
|
117
|
+
page.should_not have_content('A Test Faq')
|
|
118
|
+
page.should_not have_content('Image')
|
|
119
|
+
page.should_not have_content('Faq with full metadata')
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context 'Faqs#show' do
|
|
124
|
+
before { visit faq_path('2011/05/01/full-metadata') }
|
|
125
|
+
|
|
126
|
+
it 'should have content' do
|
|
127
|
+
page.should have_content('Faq with full metadata') # title
|
|
128
|
+
page.should have_content('Posted on 1 May 2011') # publish date
|
|
129
|
+
page.should have_content('by John Smith') # author
|
|
130
|
+
|
|
131
|
+
# body
|
|
132
|
+
page.should have_content('First paragraph of content.')
|
|
133
|
+
page.should have_content('Second paragraph of content.')
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'should not show the summary' do
|
|
137
|
+
page.should_not have_content('This is another custom & test summary.')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'should preserve whitespace on code blocks' do
|
|
141
|
+
page.source.should match '<pre><code>First line of code.
 Second line of code.
</code></pre>'
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'should allow calling Rails helpers via ERB tags' do
|
|
145
|
+
page.source.should match('<p>Paragraph created by Rails helper</p>')
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
context 'Faqs#feed' do
|
|
150
|
+
before { visit faqs_feed_path }
|
|
151
|
+
|
|
152
|
+
it 'should be xml format type' do
|
|
153
|
+
page.response_headers['Content-Type'].should == 'application/atom+xml; charset=utf-8'
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'should be valid xml' do
|
|
157
|
+
lambda do
|
|
158
|
+
Nokogiri::XML::Reader(page.source)
|
|
159
|
+
end.should_not raise_error
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'should contain the correct number of entries' do
|
|
163
|
+
Nokogiri::XML(page.source).search('entry').size.should == 4
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'should contain an entry that is properly constructed' do
|
|
167
|
+
entry = Nokogiri::XML(page.source).search('entry').first
|
|
168
|
+
|
|
169
|
+
entry.search('title').text.should == 'Faq with full metadata'
|
|
170
|
+
entry.search('author').first.search('name').text.should == 'John Smith'
|
|
171
|
+
entry.search('author').first.search('email').text.should == 'john.smith@example.com'
|
|
172
|
+
entry.search('published').text.should == '2011-05-01T00:00:00Z'
|
|
173
|
+
entry.search('content').text == "\n <p>First paragraph of content.</p>\n\n<p>Second paragraph of content.</p>\n\n "
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context 'Faqs#show with invalid slug' do
|
|
178
|
+
it 'should raise an not found exception' do
|
|
179
|
+
lambda do
|
|
180
|
+
visit faq_path('2011/05/01/invalid')
|
|
181
|
+
end.should raise_error(ActiveRecord::RecordNotFound)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context 'theme' do
|
|
186
|
+
before { @original_layout = Faqmarkdown::Config.options[:layout] }
|
|
187
|
+
after { Faqmarkdown::Config.options[:layout] = @original_layout }
|
|
188
|
+
|
|
189
|
+
it 'should use the application layout by default' do
|
|
190
|
+
visit faqs_path
|
|
191
|
+
page.should_not have_content('A faqmarkdown faq')
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it 'should use the Faqmarkdown layout when using theme' do
|
|
195
|
+
ActiveSupport::Deprecation.silence do
|
|
196
|
+
Faqmarkdown::Config.options[:use_theme] = true
|
|
197
|
+
visit faqs_path
|
|
198
|
+
page.should have_content('A faqmarkdown faq')
|
|
199
|
+
Faqmarkdown::Config.options[:use_theme] = false
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'should use the built-in layout when the global option is set to true' do
|
|
204
|
+
Faqmarkdown::Config.options[:layout] = 'custom_layout'
|
|
205
|
+
visit faqs_path
|
|
206
|
+
page.should have_content('A custom layout')
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
|
2
|
+
|
|
3
|
+
<!--more-->
|
|
4
|
+
|
|
5
|
+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Faq with full metadata
|
|
3
|
+
author: John Smith
|
|
4
|
+
email: john.smith@example.com
|
|
5
|
+
summary: This is another custom & test summary.
|
|
6
|
+
categories:
|
|
7
|
+
- full
|
|
8
|
+
- metadata
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
First paragraph of content.
|
|
12
|
+
|
|
13
|
+
<!--more-->
|
|
14
|
+
|
|
15
|
+
Second paragraph of content.
|
|
16
|
+
|
|
17
|
+
First line of code.
|
|
18
|
+
Second line of code.
|
|
19
|
+
|
|
20
|
+
<%= content_tag :p, "Paragraph created by Rails helper" %>
|