├── fixtures └── disqus-app │ ├── source │ ├── basic.html.erb │ ├── count.html.erb │ ├── options2.html.erb │ ├── per_call_options1.html.erb │ ├── per_call_options2.html.erb │ └── options1.html.erb │ └── config.rb ├── .gitignore ├── Rakefile ├── lib ├── middleman-disqus │ ├── version.rb │ ├── count.erb │ ├── embed.erb │ └── extension.rb └── middleman-disqus.rb ├── .travis.yml ├── Gemfile ├── spec ├── spec_helper.rb └── features │ ├── count_spec.rb │ ├── basic_spec.rb │ ├── options2_spec.rb │ ├── per_call_options1_spec.rb │ ├── options1_spec.rb │ └── per_call_options2_spec.rb ├── CHANGELOG.md ├── middleman-disqus.gemspec ├── LICENSE └── README.md /fixtures/disqus-app/source/basic.html.erb: -------------------------------------------------------------------------------- 1 | <%= disqus %> 2 | -------------------------------------------------------------------------------- /fixtures/disqus-app/source/count.html.erb: -------------------------------------------------------------------------------- 1 | <%= disqus_count %> 2 | -------------------------------------------------------------------------------- /fixtures/disqus-app/config.rb: -------------------------------------------------------------------------------- 1 | activate :disqus do |d| 2 | d.shortname = 'test-name' 3 | end 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore bundler lock file 2 | Gemfile.lock 3 | pkg 4 | *.gem 5 | tmp/ 6 | .ruby-version 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | RSpec::Core::RakeTask.new(:spec) 4 | 5 | task :default => :spec 6 | -------------------------------------------------------------------------------- /lib/middleman-disqus/version.rb: -------------------------------------------------------------------------------- 1 | module Middleman 2 | module Disqus 3 | VERSION = '1.2.0' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /fixtures/disqus-app/source/options2.html.erb: -------------------------------------------------------------------------------- 1 | --- 2 | disqus_category_id: 4 3 | disqus_disable_mobile: false 4 | --- 5 | <%= disqus %> 6 | -------------------------------------------------------------------------------- /fixtures/disqus-app/source/per_call_options1.html.erb: -------------------------------------------------------------------------------- 1 | <%= disqus disqus_url: 'http://example.com/2012/the-best-day-of-my-life.html' %> 2 | -------------------------------------------------------------------------------- /lib/middleman-disqus.rb: -------------------------------------------------------------------------------- 1 | require 'middleman-core' 2 | require 'middleman-disqus/version' 3 | 4 | ::Middleman::Extensions.register(:disqus) do 5 | require 'middleman-disqus/extension' 6 | ::Middleman::DisqusExtension 7 | end 8 | -------------------------------------------------------------------------------- /fixtures/disqus-app/source/per_call_options2.html.erb: -------------------------------------------------------------------------------- 1 | --- 2 | disqus_identifier: /2012/the-best-day-of-my-life.html 3 | disqus_url: http://example.com/2015/better-day-of-my-life.html 4 | --- 5 | <%= disqus disqus_url: 'http://example.com/2012/the-best-day-of-my-life.html' %> 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - ruby-head 4 | - 2.2.4 5 | - 2.1 6 | - 2.0 7 | - jruby-head 8 | before_install: 9 | - gem update --system 10 | - gem update bundler 11 | 12 | matrix: 13 | allow_failures: 14 | - rvm: ruby-head 15 | - rvm: jruby-head 16 | -------------------------------------------------------------------------------- /fixtures/disqus-app/source/options1.html.erb: -------------------------------------------------------------------------------- 1 | --- 2 | disqus_identifier: /2012/the-best-day-of-my-life.html 3 | disqus_title: The best day of my life 4 | disqus_url: http://example.com/2012/the-best-day-of-my-life.html 5 | disqus_category_id: 4 6 | disqus_disable_mobile: true 7 | --- 8 | <%= disqus %> 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in middleman-disqus.gemspec 4 | gemspec 5 | 6 | group :development do 7 | gem 'rake', '~> 0.9.2' 8 | gem 'rdoc', '~> 3.9' 9 | gem 'yard', '~> 0.9' 10 | end 11 | 12 | group :test do 13 | gem 'rspec', '~> 3.4' 14 | gem 'capybara', '~> 2.5' 15 | end 16 | -------------------------------------------------------------------------------- /lib/middleman-disqus/count.erb: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | require 'capybara/rspec' 3 | 4 | require 'middleman-core' 5 | require 'middleman-core/rack' 6 | 7 | PROJECT_ROOT_PATH = File.dirname(File.dirname(__FILE__)) 8 | require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-disqus') 9 | 10 | FIXTURE_ROOT_PATH = File.join(PROJECT_ROOT_PATH, 'fixtures', 'disqus-app') 11 | ENV['MM_ROOT'] = FIXTURE_ROOT_PATH 12 | 13 | middleman_app = ::Middleman::Application.new 14 | 15 | Capybara.app = ::Middleman::Rack.new(middleman_app).to_app do 16 | set :root, FIXTURE_ROOT_PATH 17 | set :environment, :development 18 | set :show_exceptions, false 19 | end 20 | -------------------------------------------------------------------------------- /spec/features/count_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'count', :type => :feature do 4 | before do 5 | visit '/count.html' 6 | end 7 | 8 | it 'has the disqus JS element set up' do 9 | expect(page.html).to include "var disqus_shortname = 'test-name'" 10 | expect(page.html).to include 'disqus.com/count.js' 11 | expect(page.html).to_not include 'var disqus_identifier' 12 | expect(page.html).to_not include 'var disqus_title' 13 | expect(page.html).to_not include 'var disqus_url' 14 | expect(page.html).to_not include 'var disqus_category_id' 15 | expect(page.html).to_not include 'var disqus_disable_mobile' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.2.0 (2016-01-11) 2 | 3 | * Add support for Middleman v4 (please continue to use middleman-disqus 1.1 if you need v3 support). 4 | * Moved all tests from Cucumber to Capybara / RSpec. 5 | 6 | ## 1.0.0 (2014-08-06) 7 | 8 | * Add support for Disqus JavaScript configuration variables using per page 9 | YAML Frontmatter. 10 | * Add support for Disqus count.js to allow displaying of comment counts. 11 | * General refactoring of codebase. 12 | 13 | ## 0.0.3 (2013-07-16) 14 | 15 | * Restructure code to conform with new extension style. 16 | * Update middleman dependency to v3.1.0 and up. 17 | * Add tests & travis-ci.org configuration file. 18 | 19 | ## 0.0.2 (2013-06-23) 20 | 21 | * Initial release. 22 | -------------------------------------------------------------------------------- /spec/features/basic_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'basic', :type => :feature do 4 | before do 5 | visit '/basic.html' 6 | end 7 | 8 | it 'has the disqus thread element' do 9 | expect(page).to have_selector '#disqus_thread' 10 | end 11 | 12 | it 'has the disqus JS element set up' do 13 | expect(page.html).to include 'disqus.com/embed.js' 14 | expect(page.html).to include "var disqus_shortname = 'test-name'" 15 | expect(page.html).to_not include 'var disqus_identifier' 16 | expect(page.html).to_not include 'var disqus_title' 17 | expect(page.html).to_not include 'var disqus_url' 18 | expect(page.html).to_not include 'var disqus_category_id' 19 | expect(page.html).to_not include 'var disqus_disable_mobile' 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/features/options2_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'options2', :type => :feature do 4 | before do 5 | visit '/options2.html' 6 | end 7 | 8 | it 'has the disqus thread element' do 9 | expect(page).to have_selector '#disqus_thread' 10 | end 11 | 12 | it 'has the disqus JS element set up' do 13 | expect(page.html).to include 'disqus.com/embed.js' 14 | expect(page.html).to include "var disqus_shortname = 'test-name'" 15 | expect(page.html).to include 'var disqus_category_id = 4' 16 | expect(page.html).to include 'var disqus_disable_mobile = false' 17 | expect(page.html).to_not include 'var disqus_identifier' 18 | expect(page.html).to_not include 'var disqus_title' 19 | expect(page.html).to_not include 'var disqus_url' 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/features/per_call_options1_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'per_call_options1', :type => :feature do 4 | before do 5 | visit '/per_call_options1.html' 6 | end 7 | 8 | it 'has the disqus thread element' do 9 | expect(page).to have_selector '#disqus_thread' 10 | end 11 | 12 | it 'has the disqus JS element set up' do 13 | expect(page.html).to include 'disqus.com/embed.js' 14 | expect(page.html).to include "var disqus_shortname = 'test-name'" 15 | expect(page.html).to include "var disqus_url = 'http://example.com/2012/the-best-day-of-my-life.html'" 16 | expect(page.html).to_not include 'var disqus_identifier' 17 | expect(page.html).to_not include 'var disqus_title' 18 | expect(page.html).to_not include 'var disqus_category_id' 19 | expect(page.html).to_not include 'var disqus_disable_mobile' 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/features/options1_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'options1', :type => :feature do 4 | before do 5 | visit '/options1.html' 6 | end 7 | 8 | it 'has the disqus thread element' do 9 | expect(page).to have_selector '#disqus_thread' 10 | end 11 | 12 | it 'has the disqus JS element set up' do 13 | expect(page.html).to include 'disqus.com/embed.js' 14 | expect(page.html).to include "var disqus_shortname = 'test-name'" 15 | expect(page.html).to include 'var disqus_category_id = 4' 16 | expect(page.html).to include 'var disqus_disable_mobile = true' 17 | expect(page.html).to include "var disqus_identifier = '/2012/the-best-day-of-my-life.html'" 18 | expect(page.html).to include "var disqus_url = 'http://example.com/2012/the-best-day-of-my-life.html'" 19 | expect(page.html).to include "var disqus_title = 'The best day of my life'" 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /middleman-disqus.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path('../lib', __FILE__) 3 | require 'middleman-disqus/version' 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'middleman-disqus' 7 | s.version = Middleman::Disqus::VERSION 8 | s.authors = ['Simon Rice', 'Luke Antins'] 9 | s.email = ['im@simonrice.com'] 10 | s.homepage = 'http://github.com/simonrice/middleman-disqus' 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 17 | 18 | s.files = `git ls-files`.split("\n") 19 | s.test_files = `git ls-files -- {features,fixtures}/*`.split("\n") 20 | s.require_paths = ['lib'] 21 | 22 | s.add_runtime_dependency('middleman-core', ['~> 4.0']) 23 | end 24 | -------------------------------------------------------------------------------- /spec/features/per_call_options2_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'per_call_options2', :type => :feature do 4 | before do 5 | visit '/per_call_options2.html' 6 | end 7 | 8 | it 'has the disqus thread element' do 9 | expect(page).to have_selector '#disqus_thread' 10 | end 11 | 12 | it 'has the disqus JS element set up' do 13 | expect(page.html).to include 'disqus.com/embed.js' 14 | expect(page.html).to include "var disqus_shortname = 'test-name'" 15 | expect(page.html).to include "var disqus_identifier = '/2012/the-best-day-of-my-life.html'" 16 | expect(page.html).to include "var disqus_url = 'http://example.com/2012/the-best-day-of-my-life.html'" 17 | expect(page.html).to_not include "var disqus_url = 'http://example.com/2015/the-best-day-of-my-life.html'" 18 | expect(page.html).to_not include 'var disqus_title' 19 | expect(page.html).to_not include 'var disqus_category_id' 20 | expect(page.html).to_not include 'var disqus_disable_mobile' 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Simon Rice 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | 'Software'), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/middleman-disqus/embed.erb: -------------------------------------------------------------------------------- 1 |
2 | 29 | 30 | comments powered by Disqus 31 | -------------------------------------------------------------------------------- /lib/middleman-disqus/extension.rb: -------------------------------------------------------------------------------- 1 | require 'middleman-core' 2 | require 'active_support' 3 | require 'active_support/core_ext/hash/indifferent_access' 4 | 5 | module Middleman 6 | class DisqusExtension < Extension 7 | option :shortname, nil, 'Your short name for Disqus' 8 | 9 | def initialize(app, options_hash={}, &block) 10 | super 11 | # place in class variable so helpers can access 12 | @@options = options 13 | end 14 | 15 | def self.options(options = {}) 16 | options = options.to_hash.map do |k,obj| 17 | k =~ /^disqus_(.*)$/ ? [$1, obj] : nil 18 | end 19 | options = Hash[options.compact] 20 | @@options.to_h.merge(options).with_indifferent_access 21 | end 22 | 23 | helpers do 24 | def disqus(call_options = {}) 25 | page_options = current_resource.metadata[:page].merge(call_options) 26 | @options = Middleman::DisqusExtension.options(page_options) 27 | return '' unless @options[:shortname] 28 | 29 | file = File.join(File.dirname(__FILE__), 'embed.erb') 30 | ERB.new(File.read(file), 0, '>').result(binding) 31 | end 32 | 33 | def disqus_count 34 | @options = Middleman::DisqusExtension.options 35 | return '' unless @options[:shortname] 36 | 37 | file = File.join(File.dirname(__FILE__), 'count.erb') 38 | ERB.new(File.read(file), 0, '>').result(binding) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Middleman Disqus 2 | 3 | [](https://travis-ci.org/simonrice/middleman-disqus) 4 | [](http://badge.fury.io/rb/middleman-disqus) 5 | [](https://gemnasium.com/simonrice/middleman-disqus) 6 | [](https://codeclimate.com/github/simonrice/middleman-disqus) 7 | 8 | Middleman-Disqus is a [Middleman](https://github.com/middleman/middleman) 9 | extension that generates the Disqus embed code, and keeps your config 10 | in `config.rb`, where it belongs. 11 | 12 | ## Installation 13 | 14 | 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 | 49 | Comments 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 64 | 65 | ```ruby 66 | activate :disqus do |d| 67 | # Disqus shotname, without '.disqus.com' on the end (default = nil) 68 | d.shortname = 'your_shortname' 69 | end 70 | ``` 71 | 72 | ## Configuration: YAML Frontmatter 73 | 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] 78 | 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 | --- 87 | 88 | Page with YAML Frontmatter. 89 | ``` 90 | 91 | ## IMPORTANT: Do not use real shortnames during development 92 | 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: 103 | 104 | ```ruby 105 | # config.rb 106 | configure :development do 107 | activate :disqus do |d| 108 | # using a special shortname 109 | d.shortname = "development-shortname" 110 | # or setting to `nil` will stop Disqus loading 111 | d.shortname = nil 112 | end 113 | end 114 | 115 | configure :build do 116 | activate :disqus do |d| 117 | # using a different shortname for production builds 118 | d.shortname = "production-shortname" 119 | end 120 | end 121 | ``` 122 | 123 | ## License 124 | 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 129 | --------------------------------------------------------------------------------