buttercms 0.0.8 → 0.1.1

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: e8cfd9c6d155d1d6af4e7ce36410d02caec5f155
4
- data.tar.gz: 3e7eea1416ff87e322a4af8c55f63741a4e8c46c
3
+ metadata.gz: 93c8abdd5de9af65a95f692c1f3476bee23346a9
4
+ data.tar.gz: 49b2f0ed710503c5703cb86618aa9970f2c6a8ad
5
5
  SHA512:
6
- metadata.gz: 67b0cc540d0b9c3ea17fbaac22cc2712b1d173fdeb7c6c94900412d239635f92da05200747c3acb94923090179e288012cae745b88bb9ce9299702e028a63dba
7
- data.tar.gz: c92fce92b78b7989aef456e793433957e1087dade9fa5bd39b5c051772e47543ec2a4e1042d0ed6ffb9832c9f36acb32682eededaea28a144f552089a3759e71
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
- Mount the Buttercms engine in your config/routes.rb and define your blog path.
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:: ruby
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
- # In config/initializers/butter.rb
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
- Nice job. You've now got a blog running natively in your Rails project. Nothing but Ruby goodness. (No PHP scripts here ;))
39
+ That's it! Youve 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
- begin
7
- Rails.application.config.blog_layout
8
- rescue NoMethodError
9
- # Default to the included layout.
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
- # Rails 3
19
- if defined? Buttercms::BUTTER_CMS_TOKEN
20
- return Buttercms::BUTTER_CMS_TOKEN
21
- # Rails 4
22
- elsif defined? Rails.application.secrets.BUTTER_CMS_TOKEN
23
- return Rails.application.secrets.BUTTER_CMS_TOKEN
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
- begin
65
- # Check for overridden template.
66
- render template: Rails.application.config.blog_home_template
67
- rescue NoMethodError
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
- begin
76
- # Check for overridden template.
77
- render template: Rails.application.config.blog_post_template
78
- rescue NoMethodError
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
- begin
91
- # Check for overridden template.
92
- render template: Rails.application.config.blog_author_template
93
- rescue NoMethodError
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
- begin
104
- # Check for overridden template.
105
- render template: Rails.application.config.blog_category_template
106
- rescue NoMethodError
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
@@ -1,5 +1,21 @@
1
1
  require "buttercms/engine"
2
2
 
3
3
  module Buttercms
4
- # Some engines choose to use this file to put global configuration options for their engine. It's a relatively good idea, so if you want to offer configuration options, the file where your engine's module is defined is perfect for that. Place the methods inside the module and you'll be good to go.
5
- end
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
@@ -1,3 +1,3 @@
1
1
  module Buttercms
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0.8
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-26 00:00:00.000000000 Z
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