middleman-disqus 0.0.3 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 201d480dd074109ef44da43e8623fbeaa449e876
4
- data.tar.gz: 2aa8c23e7242cc564abd86a21179d96bc3a03514
3
+ metadata.gz: d552d193d5f180f06a48f7e49e4ce16deb72e467
4
+ data.tar.gz: 50615410d5a80e524dad1f174f0b1a55b0b7df29
5
5
  SHA512:
6
- metadata.gz: b9381633cd561c76b96071e1c962530889a0bfa482abef5d7a8fd5b0c174ea9a5fe8c2275fa4dd84cec04586c392b258057dec41a685bf962be5c88ea12083a5
7
- data.tar.gz: 8ac8c992d2fd6d70779ed23d5077cd1cd1ef2153294b0a2443be0071f9df5ce9fb9657cce55800a1f491d884ef91cbf891511d27cad0e19a9c5ccdea4e8b9e42
6
+ metadata.gz: 86258d1c47c86f6def9738621cfcb8cc3a68e6ce3923783496a228d0786f75565d807d1285e61706327dc2db92d340fe80b898230b25c0c4b8bde2bf3e3c2cf8
7
+ data.tar.gz: 063392125c3309b40cdbe86df182eb0bc7f540e6c95eb878d5d7fbbf8e1edcc0bae7dce3b2c3c5eb8777e8869f805dd8daca0da6ff004974d358e7b9a9fc477d
data/.travis.yml CHANGED
@@ -1,18 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - ruby-head
4
+ - 2.1.2
5
+ - 2.1.1
6
+ - 2.1.0
3
7
  - 2.0.0
4
8
  - 1.9.3
5
- - 1.9.2
6
- - jruby-18mode
7
- - jruby-19mode
9
+ - rbx-2
8
10
  - rbx-19mode
9
- - ruby-head
10
11
  - jruby-head
11
- - 1.8.7
12
- - ree
12
+ - jruby-19mode
13
13
 
14
14
  matrix:
15
15
  allow_failures:
16
16
  - rvm: ruby-head
17
17
  - rvm: jruby-head
18
- - rvm: rbx-18mode
18
+ - rvm: rbx-2
data/HISTORY.md ADDED
@@ -0,0 +1,16 @@
1
+ ## 1.0.0 (2014-08-06)
2
+
3
+ * Add support for Disqus JavaScript configuration variables using per page
4
+ YAML Frontmatter.
5
+ * Add support for Disqus count.js to allow displaying of comment counts.
6
+ * General refactoring of codebase.
7
+
8
+ ## 0.0.3 (2013-07-16)
9
+
10
+ * Restructure code to conform with new extension style.
11
+ * Update middleman dependency to v3.1.0 and up.
12
+ * Add tests & travis-ci.org configuration file.
13
+
14
+ ## 0.0.2 (2013-06-23)
15
+
16
+ * Initial release.
data/README.md CHANGED
@@ -2,66 +2,127 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/simonrice/middleman-disqus.png)](https://travis-ci.org/simonrice/middleman-disqus)
4
4
  [![Gem Version](https://badge.fury.io/rb/middleman-disqus.png)](http://badge.fury.io/rb/middleman-disqus)
5
- [![Dependency Status](https://gemnasium.com/simonrice/middleman-disqus.png)](https://gemnasium.com/simonrice/middleman-disqus)
5
+ [![Dependency Status](https://gemnasium.com/simonrice/middleman-disqus.png)](https://gemnasium.com/simonrice/middleman-disqus)
6
6
  [![Code Climate](https://codeclimate.com/github/simonrice/middleman-disqus.png)](https://codeclimate.com/github/simonrice/middleman-disqus)
7
7
 
8
8
  Middleman-Disqus is a [Middleman](https://github.com/middleman/middleman)
9
9
  extension that generates the Disqus embed code, and keeps your config
10
10
  in `config.rb`, where it belongs.
11
11
 
12
- This plugin is based on [middleman-google-analytics](https://github.com/MrJoy/middleman-google-analytics).
13
-
14
12
  ## Installation
15
13
 
16
- If you already have a Middleman project:
17
14
 
18
- Add `gem "middleman-disqus"` to your `Gemfile` then open up your `config.rb` and add:
15
+ 1. Specify the dependency in your project's `Gemfile`:
16
+
17
+ ```ruby
18
+ # Gemfile
19
+ gem "middleman-disqus"
20
+ ```
21
+
22
+ 2. Activate the Disqus extension in your project's `config.rb`.
23
+ **(n.b. read [important information about shortnames](#important-do-not-use-real-shortnames-during-development))**
24
+
25
+ ```ruby
26
+ # config.rb
27
+ activate :disqus do |d|
28
+ d.shortname = 'your-shortname' # Replace with your Disqus shortname.
29
+ end
30
+ ```
31
+
32
+ 3. In your layout or template call `disqus` and/or `discus_count` and
33
+ include the results in the page:
34
+
35
+ **Haml:**
36
+
37
+ ```haml
38
+ / link with `#disqus_thread` is optional if not using `disqus_count` -->
39
+ %a{:href => "http://example.com/foo.html#disqus_thread"} Comments
40
+
41
+ = disqus
42
+ = disqus_count
43
+ ```
44
+
45
+ **ERB:**
46
+
47
+ ```erb
48
+ <!-- link with `#disqus_thread` is optional if not using `disqus_count` -->
49
+ <a href="http://example.com/foo.html#disqus_thread">Comments</a>
50
+
51
+ <%= disqus %>
52
+ <%= disqus_count %>
53
+ ```
54
+
55
+ ## Helper methods
56
+
57
+ The following helper methods are available within your templates:
58
+
59
+ - `disqus` will include the Disqus embed.js code and display comments.
60
+ - `disqus_count` will include the Disqus count.js code for displaying
61
+ a comment count on links when you set #disqus_thread to the href attribute.
62
+
63
+ ## Configuration: config.rb
19
64
 
20
65
  ```ruby
21
- # Activate Disqus extension
22
66
  activate :disqus do |d|
23
- d.shortname = "your_shortname"
67
+ # Disqus shotname, without '.disqus.com' on the end (default = nil)
68
+ d.shortname = 'your_shortname'
24
69
  end
25
70
  ```
26
71
 
27
- Then, in your relevant layout(s), after your footer, call `disqus` and
28
- include the results in the page. For example, in HAML:
72
+ ## Configuration: YAML Frontmatter
29
73
 
30
- ```haml
31
- = disqus
32
- ```
74
+ You can set per page configuration variables in the YAML Fontmatter, these
75
+ are used as parameters for Disqus' behaviors and settings.
76
+
77
+ For full details about what they do, see [Disqus JavaScript configuration variables][djcv]
33
78
 
34
- Or ERB:
79
+ ```yaml
80
+ ---
81
+ disqus_identifier: /2012/the-best-day-of-my-life.html
82
+ disqus_title: The best day of my life
83
+ disqus_url: http://example.com/2012/the-best-day-of-my-life.html
84
+ disqus_category_id: 4
85
+ disqus_disable_mobile: true
86
+ ---
35
87
 
36
- ```erb
37
- <%= disqus %>
88
+ Page with YAML Frontmatter.
38
89
  ```
39
90
 
40
- ## Only Including Embed Code in Builds
91
+ ## IMPORTANT: Do not use real shortnames during development
41
92
 
42
- To include the embed code only in builds, and not when running
43
- `middleman server`, simply add environment-specific configurations in your
44
- `config.rb`:
93
+ If you use the live/production shortname during development and testing, expect
94
+ to litter your Disqus account with discussions that you can't delete!
95
+
96
+ You have two options:
97
+
98
+ - Create a special testing/development shortname for use during development.
99
+ - Only include Disqus in builds, not when running `middleman server`.
100
+
101
+ You can set different options for `build` and `development` by using
102
+ Middleman's [environment specific settings][ess], for example:
45
103
 
46
104
  ```ruby
105
+ # config.rb
47
106
  configure :development do
48
107
  activate :disqus do |d|
49
- d.shortname = false
108
+ # using a special shortname
109
+ d.shortname = "development-shortname"
110
+ # or setting to `nil` will stop Disqus loading
111
+ d.shortname = nil
50
112
  end
51
113
  end
52
114
 
53
115
  configure :build do
54
116
  activate :disqus do |d|
55
- d.shortname = "your_shortname"
117
+ # using a different shortname for production builds
118
+ d.shortname = "production-shortname"
56
119
  end
57
120
  end
58
121
  ```
59
122
 
60
- ## Usage
61
-
62
- Once you've bundled you should be able to run middleman as normal, and have it
63
- display the Disqus comments box.
64
-
65
123
  ## License
66
124
 
67
125
  Usage is provided under the MIT License. See the LICENSE file for the full details.
126
+
127
+ [ess]: http://middlemanapp.com/advanced/configuration/#environment-specific-settings
128
+ [djcv]: https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
@@ -1,10 +1,70 @@
1
- @new
2
- Feature: Adds a Disqus embed code
3
- Scenario: The Disqus embed code is added with the configured short name
1
+ Feature: Disqus Integration
2
+
3
+ Scenario: Disqus config var `shotname` is not set
4
+ Given a fixture app "disqus-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ activate :disqus do |d|
8
+ d.shortname = nil
9
+ end
10
+ """
11
+ And the Server is running
12
+ When I go to "/"
13
+ Then I should see "0" lines
14
+ When I go to "/count.html"
15
+ Then I should see "0" lines
16
+
17
+ Scenario: Basic usage, Disqus javascript is included when `shotname` is set
4
18
  Given a successfully built app at "disqus-app"
5
19
  When I cd to "build"
6
20
  Then the following files should exist:
7
21
  | index.html |
8
-
22
+ | count.html |
9
23
  And the file "index.html" should contain 'div id="disqus_thread"'
10
- And the file "index.html" should contain "dsq.src = '//test-name.disqus.com/embed.js';"
24
+ And the file "index.html" should contain "var disqus_shortname = 'test-name';"
25
+ And the file "index.html" should contain 'disqus.com/embed.js'
26
+ And the file "count.html" should contain "var disqus_shortname = 'test-name';"
27
+ And the file "count.html" should contain 'disqus.com/count.js'
28
+
29
+ Scenario: Per page Disqus variables
30
+ Given a fixture app "disqus-app"
31
+ And a file named "source/options.html.erb" with:
32
+ """
33
+ ---
34
+ disqus_identifier: /2012/the-best-day-of-my-life.html
35
+ disqus_title: The best day of my life
36
+ disqus_url: http://example.com/2012/the-best-day-of-my-life.html
37
+ disqus_category_id: 4
38
+ disqus_disable_mobile: true
39
+ ---
40
+ <%= disqus %>
41
+ """
42
+ And a successfully built app at "disqus-app"
43
+ When I cd to "build"
44
+ Then the following files should exist:
45
+ | options.html |
46
+ And the file "options.html" should contain "var disqus_identifier = '/2012/the-best-day-of-my-life.html';"
47
+ And the file "options.html" should contain "var disqus_title = 'The best day of my life';"
48
+ And the file "options.html" should contain "var disqus_url = 'http://example.com/2012/the-best-day-of-my-life.html';"
49
+ And the file "options.html" should contain "var disqus_category_id = 4;"
50
+ And the file "options.html" should contain "var disqus_disable_mobile = true;"
51
+
52
+ Scenario: Only set a couple of per page Disqus variables
53
+ Given a fixture app "disqus-app"
54
+ And a file named "source/options.html.erb" with:
55
+ """
56
+ ---
57
+ disqus_category_id: 4
58
+ disqus_disable_mobile: false
59
+ ---
60
+ <%= disqus %>
61
+ """
62
+ And a successfully built app at "disqus-app"
63
+ When I cd to "build"
64
+ Then the following files should exist:
65
+ | options.html |
66
+ And the file "options.html" should not contain "var disqus_identifier"
67
+ And the file "options.html" should not contain "var disqus_title"
68
+ And the file "options.html" should not contain "var disqus_url"
69
+ And the file "options.html" should contain "var disqus_category_id = 4;"
70
+ And the file "options.html" should contain "var disqus_disable_mobile = false;"
@@ -1,3 +1,3 @@
1
1
  activate :disqus do |d|
2
- d.shortname = "test-name"
2
+ d.shortname = 'test-name'
3
3
  end
@@ -0,0 +1 @@
1
+ <%= disqus_count %>
@@ -1,6 +1 @@
1
- ---
2
- title: Welcome to Middleman
3
- ---
4
-
5
- <p>Hello world!</p>
6
1
  <%= disqus %>
@@ -1,33 +1,7 @@
1
- require "middleman-core"
1
+ require 'middleman-core'
2
+ require 'middleman-disqus/version'
2
3
 
3
- class Disqus < ::Middleman::Extension
4
- option :shortname, false, "Your short name for Disqus"
5
-
6
- def initialize(app, options_hash={}, &block)
7
- super
8
-
9
- app.set :disqus_shortname, options.shortname
10
- end
11
-
12
- helpers do
13
- def disqus
14
- if disqus_shortname
15
- %Q{<div id="disqus_thread"></div>
16
- <script type="text/javascript">
17
- //<![CDATA[
18
- (function() {
19
- var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
20
- dsq.src = '//#{disqus_shortname}.disqus.com/embed.js';
21
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
22
- })();
23
- //]]>
24
- </script>
25
- <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
26
- <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
27
- </script>}
28
- end
29
- end
30
- end
4
+ ::Middleman::Extensions.register(:disqus) do
5
+ require 'middleman-disqus/extension'
6
+ ::Middleman::DisqusExtension
31
7
  end
32
-
33
- ::Middleman::Extensions.register(:disqus, Disqus)
@@ -0,0 +1,11 @@
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ var disqus_shortname = '<%= @options[:shortname] %>';
4
+ (function () {
5
+ var s = document.createElement('script'); s.async = true;
6
+ s.type = 'text/javascript';
7
+ s.src = '//' + disqus_shortname + '.disqus.com/count.js';
8
+ (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
9
+ }());
10
+ //]]>
11
+ </script>
@@ -0,0 +1,20 @@
1
+ <div id="disqus_thread"></div>
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ <% @options.each do |key, value| %>
5
+ <% if value.is_a?(String) %>
6
+ var disqus_<%= key %> = '<%= value %>';
7
+ <% elsif [Fixnum, FalseClass, TrueClass].include?(value.class) %>
8
+ var disqus_<%= key %> = <%= value %>;
9
+ <% end %>
10
+ <% end %>
11
+
12
+ (function() {
13
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
14
+ dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
15
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
16
+ })();
17
+ //]]>
18
+ </script>
19
+ <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
20
+ <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
@@ -0,0 +1,41 @@
1
+ require "middleman-core"
2
+
3
+ module Middleman
4
+ class DisqusExtension < Extension
5
+ option :shortname, nil, "Your short name for Disqus"
6
+
7
+ def initialize(app, options_hash={}, &block)
8
+ super
9
+ # place in class variable so helpers can access
10
+ @@options = options
11
+ end
12
+
13
+ def self.options(options = {})
14
+ options = options.to_hash.map do |k,obj|
15
+ k =~ /^disqus_(.*)$/ ? [$1, obj] : nil
16
+ end
17
+ options = Hash[options.compact]
18
+ @@options.to_h.merge(options).with_indifferent_access
19
+ end
20
+
21
+ helpers do
22
+ def disqus
23
+ page_options = current_resource.metadata[:page]
24
+ @options = Middleman::DisqusExtension.options(page_options)
25
+ return '' unless @options[:shortname]
26
+
27
+ file = File.join(File.dirname(__FILE__), 'embed.erb')
28
+ ERB.new(File.read(file), 0, '>').result(binding)
29
+ end
30
+
31
+ def disqus_count
32
+ @options = Middleman::DisqusExtension.options
33
+ return '' unless @options[:shortname]
34
+
35
+ file = File.join(File.dirname(__FILE__), 'count.erb')
36
+ ERB.new(File.read(file), 0, '>').result(binding)
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Disqus
3
- VERSION = "0.0.3"
3
+ VERSION = '1.0.0'
4
4
  end
5
- end
5
+ end
@@ -1,26 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "version"
3
+ require "middleman-disqus/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "middleman-disqus"
7
7
  s.version = Middleman::Disqus::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Simon Rice"]
8
+ s.authors = ["Simon Rice", "Luke Antins"]
10
9
  s.email = ["im@simonrice.com"]
11
10
  s.homepage = "http://github.com/simonrice/middleman-disqus"
12
- s.license = 'MIT'
13
- s.summary = %q{A Middleman plugin for adding the Disqus embed code.}
14
- # s.description = %q{A longer description of your extension}
11
+ s.license = "MIT"
12
+ s.summary = %q{Quickly integrate Disqus comments into your Middleman site}
13
+ s.description = <<-EOL
14
+ A Middleman extension to integrate Disqus into your site,
15
+ supporting Disqus configuration variables and comment counts.
16
+ EOL
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.test_files = `git ls-files -- {features,fixtures}/*`.split("\n")
19
20
  s.require_paths = ["lib"]
20
21
 
21
- # The version of middleman-core your extension depends on
22
- s.add_runtime_dependency("middleman-core", [">= 3.1.0"])
23
-
24
- # Additional dependencies
25
- # s.add_runtime_dependency("gem-name", "gem-version")
22
+ s.add_runtime_dependency("middleman-core", ["~> 3.1"])
26
23
  end
metadata CHANGED
@@ -1,51 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-disqus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Rice
8
+ - Luke Antins
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2014-09-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: middleman-core
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: 3.1.0
20
+ version: '3.1'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: 3.1.0
27
- description:
27
+ version: '3.1'
28
+ description: |
29
+ A Middleman extension to integrate Disqus into your site,
30
+ supporting Disqus configuration variables and comment counts.
28
31
  email:
29
32
  - im@simonrice.com
30
33
  executables: []
31
34
  extensions: []
32
35
  extra_rdoc_files: []
33
36
  files:
34
- - .gitignore
35
- - .travis.yml
37
+ - ".gitignore"
38
+ - ".travis.yml"
36
39
  - Gemfile
40
+ - HISTORY.md
37
41
  - LICENSE
38
42
  - README.md
39
43
  - Rakefile
40
44
  - features/disqus.feature
41
45
  - features/support/env.rb
42
46
  - fixtures/disqus-app/config.rb
43
- - fixtures/disqus-app/layouts/layout.erb
47
+ - fixtures/disqus-app/source/count.html.erb
44
48
  - fixtures/disqus-app/source/index.html.erb
45
- - fixtures/disqus-app/source/layouts/layout.erb
46
49
  - lib/middleman-disqus.rb
47
- - lib/middleman_extension.rb
48
- - lib/version.rb
50
+ - lib/middleman-disqus/count.erb
51
+ - lib/middleman-disqus/embed.erb
52
+ - lib/middleman-disqus/extension.rb
53
+ - lib/middleman-disqus/version.rb
49
54
  - middleman-disqus.gemspec
50
55
  homepage: http://github.com/simonrice/middleman-disqus
51
56
  licenses:
@@ -57,21 +62,23 @@ require_paths:
57
62
  - lib
58
63
  required_ruby_version: !ruby/object:Gem::Requirement
59
64
  requirements:
60
- - - '>='
65
+ - - ">="
61
66
  - !ruby/object:Gem::Version
62
67
  version: '0'
63
68
  required_rubygems_version: !ruby/object:Gem::Requirement
64
69
  requirements:
65
- - - '>='
70
+ - - ">="
66
71
  - !ruby/object:Gem::Version
67
72
  version: '0'
68
73
  requirements: []
69
74
  rubyforge_project:
70
- rubygems_version: 2.0.3
75
+ rubygems_version: 2.2.0
71
76
  signing_key:
72
77
  specification_version: 4
73
- summary: A Middleman plugin for adding the Disqus embed code.
78
+ summary: Quickly integrate Disqus comments into your Middleman site
74
79
  test_files:
75
80
  - features/disqus.feature
76
81
  - features/support/env.rb
77
- has_rdoc:
82
+ - fixtures/disqus-app/config.rb
83
+ - fixtures/disqus-app/source/count.html.erb
84
+ - fixtures/disqus-app/source/index.html.erb
@@ -1,11 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Test</title>
6
- </head>
7
-
8
- <body class="<%= page_classes %>">
9
- <%= yield %>
10
- </body>
11
- </html>
@@ -1,11 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Test</title>
6
- </head>
7
-
8
- <body class="<%= page_classes %>">
9
- <%= yield %>
10
- </body>
11
- </html>
@@ -1 +0,0 @@
1
- require 'middleman-disqus'