buttercms 0.0.8 → 0.1.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 +4 -4
- data/README.rst +5 -30
- data/app/controllers/buttercms/application_controller.rb +6 -4
- data/app/controllers/buttercms/blog_controller.rb +24 -27
- data/lib/buttercms.rb +18 -2
- data/lib/buttercms/version.rb +1 -1
- data/lib/generators/buttercms/install_generator.rb +15 -0
- data/lib/generators/templates/butter_initializer.rb +27 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c8abdd5de9af65a95f692c1f3476bee23346a9
|
4
|
+
data.tar.gz: 49b2f0ed710503c5703cb86618aa9970f2c6a8ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 034030908557fda92ec5ae37868d821db406264738adf7274ebe0af7693bc1537aca26b9e58420c929822a6b7ee3b6ef3ea77696d8f30779f7eaac1986a7192d
|
7
|
+
data.tar.gz: a04979ccac4f823f9ef932642a11ab0256ae9eaf0c5b1f4dbee5d9c3f1c06c55d87388bba2e1f2f11d1cd39828dd0bd999303946af95f80519458dba6aa4e8aa
|
data/README.rst
CHANGED
@@ -28,40 +28,15 @@ Add buttercms gem to your Gemfile and install it.
|
|
28
28
|
|
29
29
|
$ gem install buttercms
|
30
30
|
|
31
|
-
|
31
|
+
Now run the Butter install generator. This will create `config/initializers/butter.rb` and define a route in `config/routes.rb`. By default, your blog will live at "/blog".
|
32
32
|
|
33
|
-
.. code-block::
|
34
|
-
|
35
|
-
# In config/routes.rb
|
36
|
-
mount Buttercms::Engine => "/blog"
|
37
|
-
|
38
|
-
Grab your API token from https://buttercms.com/api_token
|
39
|
-
|
40
|
-
**Rails 4.x**
|
41
|
-
|
42
|
-
For rails 4, add `BUTTER_CMS_TOKEN` to `secrets.yml`
|
43
|
-
|
44
|
-
.. code-block:: ruby
|
45
|
-
|
46
|
-
# In config/secrets.yml
|
47
|
-
# Add your BUTTER_CMS_TOKEN to both development: and production:
|
48
|
-
development:
|
49
|
-
BUTTER_CMS_TOKEN: <your_api_token>
|
50
|
-
production:
|
51
|
-
BUTTER_CMS_TOKEN: <your_api_token>
|
52
|
-
|
53
|
-
|
54
|
-
**Rails 3.x**
|
55
|
-
|
56
|
-
For rails 3, set up a classic initializer to expose the api token to the Butter gem.
|
57
|
-
|
58
|
-
.. code-block:: ruby
|
33
|
+
.. code-block:: bash
|
59
34
|
|
60
|
-
|
61
|
-
Buttercms::BUTTER_CMS_TOKEN = <your_api_token>
|
35
|
+
$ rails g buttercms:install
|
62
36
|
|
37
|
+
Grab your API token from https://buttercms.com/api_token and throw it in `config/initializers/butter.rb` or set it on your ENV like so `$ export BUTTER_TOKEN=yourtokenhere"`
|
63
38
|
|
64
|
-
|
39
|
+
That's it! You’ve now got a blog running natively in your Rails project.
|
65
40
|
|
66
41
|
Check it out: localhost:3000/blog
|
67
42
|
|
@@ -3,11 +3,13 @@ module Buttercms
|
|
3
3
|
layout :get_layout
|
4
4
|
|
5
5
|
def get_layout
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if defined? Buttercms.configuration
|
7
|
+
if defined? Buttercms.configuration.blog_layout
|
8
|
+
return Buttercms.configuration.blog_layout
|
9
|
+
end
|
10
10
|
end
|
11
|
+
|
12
|
+
# Default to the included layout.
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -4,8 +4,6 @@ require 'rest-client'
|
|
4
4
|
|
5
5
|
module Buttercms
|
6
6
|
|
7
|
-
# Displays a default blog post with instructions on getting a personal token.
|
8
|
-
DEFAULT_TOKEN = 'f97d131d955f48af0769a4c827bb47728cbd5d05'
|
9
7
|
API_URL = 'https://buttercms.com/api/'
|
10
8
|
|
11
9
|
class BlogController < ApplicationController
|
@@ -15,15 +13,15 @@ module Buttercms
|
|
15
13
|
end
|
16
14
|
|
17
15
|
def get_token
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
return DEFAULT_TOKEN
|
16
|
+
|
17
|
+
# Make sure the Buttercms has been initialized.
|
18
|
+
if defined? Buttercms.configuration
|
19
|
+
if defined? Buttercms.configuration.token
|
20
|
+
return Buttercms.configuration.token
|
21
|
+
end
|
26
22
|
end
|
23
|
+
|
24
|
+
raise Exception.new("/config/intitializer/butter.rb is missing. Please run $ rails g buttercms:install")
|
27
25
|
end
|
28
26
|
|
29
27
|
def make_request(path)
|
@@ -61,10 +59,10 @@ module Buttercms
|
|
61
59
|
@previous_page = response_json['previous_page']
|
62
60
|
@recent_posts = response_json['results']
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
if defined? Buttercms.configuration
|
63
|
+
if !Buttercms.configuration.blog_home_template.nil?
|
64
|
+
render template: Buttercms.configuration.blog_home_template
|
65
|
+
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
@@ -72,11 +70,10 @@ module Buttercms
|
|
72
70
|
response = make_request("#{API_URL}posts/#{params[:slug]}")
|
73
71
|
@post = JSON.parse(response)
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# Default to normal blog post template.
|
73
|
+
if defined? Buttercms.configuration
|
74
|
+
if !Buttercms.configuration.blog_post_template.nil?
|
75
|
+
render template: Buttercms.configuration.blog_post_template
|
76
|
+
end
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
@@ -87,10 +84,10 @@ module Buttercms
|
|
87
84
|
@last_name = response_json['last_name']
|
88
85
|
@recent_posts = response_json['recent_posts']
|
89
86
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
if defined? Buttercms.configuration
|
88
|
+
if !Buttercms.configuration.blog_author_template.nil?
|
89
|
+
render template: Buttercms.configuration.blog_author_template
|
90
|
+
end
|
94
91
|
end
|
95
92
|
end
|
96
93
|
|
@@ -100,10 +97,10 @@ module Buttercms
|
|
100
97
|
@name = response_json['name']
|
101
98
|
@recent_posts = response_json['recent_posts']
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
if defined? Buttercms.configuration
|
101
|
+
if !Buttercms.configuration.blog_category_template.nil?
|
102
|
+
render template: Buttercms.configuration.blog_category_template
|
103
|
+
end
|
107
104
|
end
|
108
105
|
end
|
109
106
|
end
|
data/lib/buttercms.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
require "buttercms/engine"
|
2
2
|
|
3
3
|
module Buttercms
|
4
|
-
|
5
|
-
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :token, :blog_layout, :blog_home_template, :blog_post_template, :blog_author_template, :blog_category_template
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
# Displays a default blog post with instructions on getting a personal token.
|
18
|
+
@token = 'f97d131d955f48af0769a4c827bb47728cbd5d05'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/buttercms/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Buttercms
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
desc "Creates Buttercms initializer for your application"
|
6
|
+
|
7
|
+
def copy_initializer
|
8
|
+
template "butter_initializer.rb", "config/initializers/butter.rb"
|
9
|
+
route "mount Buttercms::Engine => '/blog'"
|
10
|
+
|
11
|
+
puts "Butter token and route installed! See your blog at localhost:3000/blog"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Buttercms.configure do |config|
|
2
|
+
# If you added the Heroku Butter add-on, ENV["BUTTER_TOKEN"] will be defined.
|
3
|
+
# Otherwise, grab your token at https://buttercms.com/api_token and either
|
4
|
+
# paste it below or set it on your ENV like so: $ export BUTTER_TOKEN=yourtokenhere"
|
5
|
+
config.token = ENV["BUTTER_TOKEN"]
|
6
|
+
|
7
|
+
# Specify a custom layout for your blog so it matches the rest of your site.
|
8
|
+
# For example uncomment the line below and define the layout in /view/layout/blog.html.erb
|
9
|
+
# You can of course also use your existing main application layout.
|
10
|
+
# config.layout = "blog"
|
11
|
+
|
12
|
+
|
13
|
+
# You can customize any view of your blog. Here is full list of page types + settings.
|
14
|
+
# We recommend putting custom templates in views/blog/<template>.html.erb
|
15
|
+
|
16
|
+
# This is the blog home page. Route: /blog
|
17
|
+
# config.home_template = "blog/home"
|
18
|
+
|
19
|
+
# This is the blog post page. Route: /blog/:post-slug
|
20
|
+
# config.post_template = "blog/post"
|
21
|
+
|
22
|
+
# This is the author page. Route: /blog/author/:author-slug
|
23
|
+
# config.author_template = "blog/author"
|
24
|
+
|
25
|
+
# This is the category page. Route: /blog/category/:category-slug
|
26
|
+
# config.category_template = "blog/category"
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buttercms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ButterCms
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- lib/buttercms.rb
|
101
101
|
- lib/buttercms/engine.rb
|
102
102
|
- lib/buttercms/version.rb
|
103
|
+
- lib/generators/buttercms/install_generator.rb
|
104
|
+
- lib/generators/templates/butter_initializer.rb
|
103
105
|
- lib/tasks/buttercms_tasks.rake
|
104
106
|
- test/buttercms_test.rb
|
105
107
|
- test/integration/navigation_test.rb
|