refinerycms-tweets 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.
Files changed (31) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +69 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +83 -0
  5. data/Rakefile +21 -0
  6. data/app/controllers/refinery/tweets/admin/twitter_accounts_controller.rb +52 -0
  7. data/app/helpers/refinery/tweets/tweets_helper.rb +113 -0
  8. data/app/models/refinery/tweets/twitter_account.rb +59 -0
  9. data/app/views/refinery/tweets/admin/twitter_accounts/_form.html.erb +34 -0
  10. data/app/views/refinery/tweets/admin/twitter_accounts/_submenu.html.erb +16 -0
  11. data/app/views/refinery/tweets/admin/twitter_accounts/edit.html.erb +1 -0
  12. data/app/views/refinery/tweets/admin/twitter_accounts/new.html.erb +2 -0
  13. data/app/views/refinery/tweets/admin/twitter_accounts/show.html.erb +21 -0
  14. data/config/locales/en.yml +20 -0
  15. data/config/routes.rb +19 -0
  16. data/db/migrate/20101208082999_create_twitter_accounts.rb +17 -0
  17. data/lib/generators/refinery/tweets/templates/config/initializers/refinery/tweets.rb.erb +13 -0
  18. data/lib/generators/refinery/tweets/tweets_generator.rb +25 -0
  19. data/lib/refinery/tweets.rb +24 -0
  20. data/lib/refinery/tweets/configuration.rb +11 -0
  21. data/lib/refinery/tweets/engine.rb +34 -0
  22. data/lib/refinery/tweets/version.rb +5 -0
  23. data/lib/refinerycms-tweets.rb +1 -0
  24. data/licence.md +21 -0
  25. data/refinerycms-tweets.gemspec +23 -0
  26. data/spec/factories/twitter_account.rb +8 -0
  27. data/spec/models/refinery/tweets/twitter_account_spec.rb +55 -0
  28. data/spec/requests/refinery/tweets/admin/tweets_spec.rb +86 -0
  29. data/spec/spec_helper.rb +35 -0
  30. data/tasks/rspec.rake +4 -0
  31. metadata +112 -0
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ spec/dummy
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,69 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'refinerycms', :git => 'git://github.com/refinery/refinerycms.git'
6
+ gem 'refinerycms-i18n', :git => 'git://github.com/refinery/refinerycms-i18n.git'
7
+
8
+ group :development, :test do
9
+ gem 'refinerycms-testing', :git => 'git://github.com/refinery/refinerycms.git'
10
+ gem 'guard-rspec', '~> 0.6.0'
11
+ gem "capybara-email", "~> 0.1.2"
12
+
13
+
14
+ platforms :jruby do
15
+ gem 'activerecord-jdbcsqlite3-adapter'
16
+ gem 'activerecord-jdbcmysql-adapter'
17
+ gem 'activerecord-jdbcpostgresql-adapter'
18
+ gem 'jruby-openssl'
19
+ end
20
+
21
+ unless defined?(JRUBY_VERSION)
22
+ gem 'sqlite3'
23
+ gem 'mysql2'
24
+ gem 'pg'
25
+ end
26
+
27
+ platforms :mswin, :mingw do
28
+ gem 'win32console'
29
+ gem 'rb-fchange', '~> 0.0.5'
30
+ gem 'rb-notifu', '~> 0.0.4'
31
+ end
32
+
33
+ platforms :ruby do
34
+ unless ENV['TRAVIS']
35
+ require 'rbconfig'
36
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
37
+ gem 'rb-fsevent', '>= 0.3.9'
38
+ gem 'ruby_gntp'
39
+ end
40
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
41
+ gem 'rb-inotify', '>= 0.5.1'
42
+ gem 'libnotify', '~> 0.1.3'
43
+ gem 'therubyracer', '~> 0.9.9'
44
+ end
45
+ end
46
+ end
47
+
48
+ platforms :jruby do
49
+ unless ENV['TRAVIS']
50
+ require 'rbconfig'
51
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
52
+ gem 'ruby_gntp'
53
+ end
54
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
55
+ gem 'rb-inotify', '>= 0.5.1'
56
+ gem 'libnotify', '~> 0.1.3'
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ # Refinery/rails should pull in the proper versions of these
63
+ group :assets do
64
+ gem 'sass-rails'
65
+ gem 'coffee-rails'
66
+ gem 'uglifier'
67
+ end
68
+
69
+ gem 'jquery-rails'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chris Holmes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # Tweets for Refinery CMS
2
+
3
+ ## About
4
+
5
+ Tweets allows you add a Twitter feed to your site in seconds.
6
+
7
+ ## Features
8
+
9
+ - Use either a Twitter [widget](https://twitter.com/settings/widgets) or a jQuery implementation using the Public API
10
+ - JQuery implementation accepts an optional callback to override the default response rendering
11
+ - Twitter widget can be fully customised
12
+
13
+ Note: The Twitter widget doesn't require jQuery however if you choose to use the Public API jQuery is required.
14
+ I do plan to add a vanilla javascript implementation in future but pull requests are welcome!
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'refinerycms-tweets'
21
+
22
+ Next run:
23
+
24
+ bundle
25
+ rails generate refinery:tweets
26
+ rake db:migrate
27
+
28
+ Now when you start up your Refinery application, there should be a new "Twitter" tab to manage the account.
29
+
30
+ ## Usage
31
+
32
+ Just add an account and put the following into your view.
33
+
34
+ <%= tweets %>
35
+
36
+ Note: If you do not have a view template already then you will need to override one, here is an example of how to do that.
37
+
38
+ rake refinery:override view=refinery/pages/show
39
+
40
+ ## Configuration
41
+
42
+ By default the Twitter widget will be used if the twitter account has a username and widget_id. If there is a username but no widget_id
43
+ then it will fallback to use the jQuery list. This behaviour can be changed in the initializer as required.
44
+
45
+ config/initializers/refinery/tweets.rb
46
+
47
+ Refinery::Tweets.use_twitter_widget = true
48
+ Refinery::Tweets.fallback_to_jquery_tweet_list = true
49
+
50
+ ### Customising
51
+
52
+ Just pass in you options as a hash. Here is an example using the twitter widget. You can see a fill list of options in the [docs](https://dev.twitter.com/docs/embedded-timelines#customization)
53
+
54
+ <%= tweets("data-chrome"=> "noheader", "data-theme" => "dark", :callback => "testalert") %>
55
+
56
+ <%= content_for :javascripts do %>
57
+ <script>
58
+ function testalert(response){
59
+ alert(response);
60
+ }
61
+ </script>
62
+ <% end %>
63
+
64
+ In this case the callback will only be triggered if there is no widget_id.
65
+
66
+ ## Screenshot
67
+
68
+ ![Admin view of the Twitter account](http://cih-static.s3.amazonaws.com/refinerycms-tweets-screenshot.png)
69
+
70
+ ## Testing
71
+
72
+ The refinerycms-testing gem allows you to generate a dummy app within the engine to run the tests against.
73
+
74
+ rake refinery:testing:dummy_app
75
+ rake spec
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ ENGINE_PATH = File.dirname(__FILE__)
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+
11
+ if File.exists?(APP_RAKEFILE)
12
+ load 'rails/tasks/engine.rake'
13
+ end
14
+
15
+ require "refinerycms-testing"
16
+ Refinery::Testing::Railtie.load_tasks
17
+ Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
+
19
+ load File.expand_path('../tasks/rspec.rake', __FILE__)
20
+
21
+ # task :default => :spec
@@ -0,0 +1,52 @@
1
+ module Refinery
2
+ module Tweets
3
+ module Admin
4
+ class TwitterAccountsController < ::Refinery::AdminController
5
+
6
+ def show
7
+ @twitter_account = TwitterAccount.first
8
+ end
9
+
10
+ def new
11
+ @twitter_account = TwitterAccount.new
12
+ end
13
+
14
+ def create
15
+ @twitter_account = TwitterAccount.new(params[:twitter_account])
16
+
17
+ if @twitter_account.save
18
+ render :show
19
+ else
20
+ redirect_to refinery.new_tweets_admin_twitter_account_path
21
+ end
22
+ end
23
+
24
+ def edit
25
+ @twitter_account = TwitterAccount.first
26
+
27
+ if @twitter_account
28
+ render :edit
29
+ else
30
+ render :show
31
+ end
32
+ end
33
+
34
+ def update
35
+ @twitter_account = TwitterAccount.first
36
+ @twitter_account.update_attributes(params[:twitter_account])
37
+
38
+ render :show
39
+ end
40
+
41
+ def destroy
42
+ @twitter_account = TwitterAccount.first
43
+ if @twitter_account.destroy
44
+ Rails.cache.delete("refinery-twitter-account-settings")
45
+ end
46
+
47
+ redirect_to refinery.tweets_admin_twitter_account_path
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,113 @@
1
+ module Refinery
2
+ module Tweets
3
+ module TweetsHelper
4
+
5
+ # Twitter widget is enabled by default
6
+ # It can be disabled in the initializer
7
+ # config/initializers/refinery/tweets.rb
8
+ #
9
+ # The user will require a widget_id
10
+ # If there is no widget id or the widget is
11
+ # disabled in the config a simple js implementation
12
+ # using the public API is used
13
+ #
14
+ def tweets(options={})
15
+ return unless account_settings && account_settings["visible"] == true
16
+ if can_use_twitter_widget?
17
+ twitter_widget(options)
18
+ elsif can_use_jquery_tweet_list?
19
+ tweet_list(options)
20
+ end
21
+ end
22
+
23
+ def tweets_header
24
+ tweets_account_link + " on Twitter"
25
+ end
26
+
27
+ def tweets_account_link
28
+ link_to twitter_handle, refinery_tweets_url_for_account
29
+ end
30
+
31
+ def twitter_handle
32
+ "@" + account_settings["username"]
33
+ end
34
+
35
+ def refinery_tweets_url_for_account
36
+ "https://twitter.com/#{account_settings["username"]}"
37
+ end
38
+
39
+ private
40
+
41
+ # The basic tweet takes an optional js callback
42
+ # it returns a list of tweets based on
43
+ # the tweet_count and username in the
44
+ # Refinery::Tweets::TwitterAccount.account_settings
45
+ #
46
+ def tweet_list(options)
47
+ content_for :javascripts do
48
+ %Q[ <script type="text/javascript">
49
+ $(function(){function e(e){output="";
50
+ $.each(e,function(e,n){output+='<li class="refinery-tweets-list-item-'+e+"\\">";
51
+ output+=t(n.text);output+="</li>"});
52
+ $(".refinery-tweets-list").append(output)}
53
+ function t(e){var t=/(\\b(https?|ftp|file):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/ig;
54
+ return e.replace(t,"<a href='$1'>$1</a>")}$.ajax({
55
+ url:"https://api.twitter.com/1/statuses/user_timeline/#{account_settings["username"]}.json?count=#{account_settings["tweet_count"]}",
56
+ dataType:"jsonp",success:#{options[:callback] || "function(t){e(t)}"},error:function(e){console.log(e)}})})
57
+ </script>].squish.html_safe
58
+ end
59
+
60
+ %Q[<ul class="refinery-tweets-list">
61
+ <h3>#{tweets_header}</h3>
62
+ </ul>].html_safe
63
+ end
64
+
65
+ # See a full list of options here
66
+ # https://dev.twitter.com/docs/embedded-timelines#customization
67
+ #
68
+ def twitter_widget(options={})
69
+ %Q[ <a class="twitter-timeline #{options[:class]}"
70
+ #{to_html_options(options)}
71
+ data-tweet-limit=#{account_settings["tweet_count"]}
72
+ href="https://twitter.com/#{account_settings["username"]}"
73
+ data-widget-id="#{account_settings["widget_id"]}">
74
+ Tweets by @#{account_settings["username"]}</a>
75
+
76
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],
77
+ p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id))
78
+ {js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";
79
+ fjs.parentNode.insertBefore(js,fjs);}} (document,"script","twitter-wjs");
80
+ </script>
81
+ ].squish.html_safe
82
+ end
83
+
84
+ def account_settings
85
+ Refinery::Tweets::TwitterAccount.account_settings
86
+ end
87
+
88
+ def can_use_twitter_widget?
89
+ account_settings["username"] && account_settings["widget_id"].present? && Refinery::Tweets.use_twitter_widget == true
90
+ end
91
+
92
+ def can_use_jquery_tweet_list?
93
+ account_settings["username"] && Refinery::Tweets.fallback_to_jquery_tweet_list == true
94
+ end
95
+
96
+ # Convert the options to html attributes
97
+ # eg. :width => 300 would convert to width="300"
98
+ #
99
+ def to_html_options(options)
100
+ return if options.empty?
101
+ options.delete(:callback) if options[:callback].present?
102
+ options.delete(:class) if options[:class].present?
103
+
104
+ output = ""
105
+ options.each do |k, v|
106
+ output += %Q[#{k.to_s}="#{v}" ]
107
+ end
108
+
109
+ output
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,59 @@
1
+ require 'refinery/core/base_model'
2
+
3
+ module Refinery
4
+ module Tweets
5
+ class TwitterAccount < Refinery::Core::BaseModel
6
+
7
+ attr_accessible :username, :tweet_count, :widget_id, :visible
8
+
9
+ validate :only_one_account, :on => :create
10
+ validates_presence_of :username, :tweet_count
11
+
12
+ after_save :update_settings_cache
13
+
14
+ class << self
15
+
16
+ def account
17
+ first
18
+ end
19
+
20
+ def account_settings
21
+ Rails.cache.read('refinery-twitter-account-settings')
22
+ end
23
+
24
+ def update_settings!
25
+ Rails.cache.write('refinery-twitter-account-settings', generate_settings_hash!)
26
+ end
27
+
28
+ def generate_settings_hash!
29
+ settings_hash = {}
30
+ attributes = %w(username tweet_count visible widget_id)
31
+ attributes.each do |key|
32
+ settings_hash.merge!(key => account.send(key.to_sym))
33
+ end
34
+ settings_hash
35
+ end
36
+ end
37
+
38
+ def name
39
+ "Admin"
40
+ end
41
+
42
+ def title
43
+ "Admin"
44
+ end
45
+
46
+ private
47
+
48
+ def update_settings_cache
49
+ self.class.update_settings!
50
+ end
51
+
52
+ def only_one_account
53
+ if self.class.account
54
+ errors[:base] << "You can only have one Twitter account."
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ <%= form_for(@twitter_account, :url => refinery.tweets_admin_twitter_account_path, :method => form_method) do |f| %>
2
+
3
+ <%= render '/refinery/admin/error_messages',
4
+ :object => @twitter_account,
5
+ :include_object_name => true %>
6
+
7
+ <div class='field'>
8
+ <%= f.label :username, t('refinery.plugins.refinerycms_tweets.username')%>
9
+ <%= f.text_field :username %>
10
+ </div>
11
+ <% if Refinery::Tweets.config.use_twitter_widget %>
12
+ <div class='field'>
13
+ <%= f.label :widget_id, t('refinery.plugins.refinerycms_tweets.widget_id') %>
14
+ <%= f.text_field :widget_id %>
15
+ </div>
16
+ <% end %>
17
+ <div class='field'>
18
+ <%= f.label :tweet_count, t('refinery.plugins.refinerycms_tweets.tweet_count') %>
19
+ <%= f.text_field :tweet_count %>
20
+ </div>
21
+ <div class='field'>
22
+ <%= f.label :visible, t('refinery.plugins.refinerycms_tweets.visible') %>
23
+ <%= f.check_box :visible %>
24
+ </div>
25
+
26
+ <%= render '/refinery/admin/form_actions', :f => f,
27
+ :continue_editing => false,
28
+ :cancel_url => refinery.tweets_admin_twitter_account_path,
29
+ :delete_url => refinery.tweets_admin_twitter_account_path,
30
+ #:hide_delete => !current_refinery_user.can_delete?(@twitter_account),
31
+ :delete_title => t('delete', :scope => 'refinery.admin.users'),
32
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @twitter_account.username) %>
33
+
34
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <div id='actions'>
2
+ <ul>
3
+ <% if @twitter_account.nil? %>
4
+ <li <%= "class='selected'" if params[:action] == "new" %>>
5
+ <%= link_to t('refinery.plugins.refinerycms_tweets.add'), refinery.new_tweets_admin_twitter_account_path, :class => "add_icon" %>
6
+ </li>
7
+ <% else %>
8
+ <li <%= "class='selected'" if params[:action] == "edit" %>>
9
+ <%= link_to t('refinery.plugins.refinerycms_tweets.edit'), refinery.edit_tweets_admin_twitter_account_path, :class => "edit_icon" %>
10
+ </li>
11
+ <li>
12
+ <%= link_to t('refinery.plugins.refinerycms_tweets.delete'), refinery.tweets_admin_twitter_account_path, :class => "delete_icon", :method => :delete %>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ </div>
@@ -0,0 +1 @@
1
+ <%= render 'form', :form_method => :put %>
@@ -0,0 +1,2 @@
1
+ <h2><%= t('refinery.plugins.refinerycms_tweets.new_account') %></h2>
2
+ <%= render 'form', :form_method => :post %>
@@ -0,0 +1,21 @@
1
+ <%= render "submenu" %>
2
+ <div id='records'>
3
+ <% if @twitter_account %>
4
+ <h2><%= t('refinery.plugins.refinerycms_tweets.account_heading') %></h2>
5
+ <%= label_tag t('refinery.plugins.refinerycms_tweets.username') %>
6
+ <span><%= @twitter_account.username %></span>
7
+
8
+ <% if Refinery::Tweets.config.use_twitter_widget %>
9
+ <%= label_tag t('refinery.plugins.refinerycms_tweets.widget_id') %>
10
+ <span><%= @twitter_account.widget_id %></span>
11
+ <% end %>
12
+
13
+ <%= label_tag t('refinery.plugins.refinerycms_tweets.tweet_count') %>
14
+ <span><%= @twitter_account.tweet_count %></span>
15
+
16
+ <%= label_tag t('refinery.plugins.refinerycms_tweets.visible') %>
17
+ <span><%= @twitter_account.visible? ? t('refinery.plugins.refinerycms_tweets.visible_yes') : t('refinery.plugins.refinerycms_tweets.visible_no') %></span>
18
+ <% else %>
19
+ <p><strong><%= t('refinery.plugins.refinerycms_tweets.no_account') %><strong></p>
20
+ <% end %>
21
+ </div>
@@ -0,0 +1,20 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ refinerycms_tweets:
5
+ title: Twitter
6
+ add: Add a Twitter account
7
+ edit: Edit Twitter account
8
+ delete: Delete Twitter account
9
+ no_account: You don't have a Twitter account listed. Click "Add a Twitter account" to add your account.
10
+ account_heading: Your Twitter Account
11
+ new_account: Add a Twitter Account
12
+ account: Twitter account
13
+ username: Username
14
+ username_help: Your Twitter username, the @ prefix is not required.
15
+ tweet_count: Number of tweets to display
16
+ widget_id: Widget id
17
+ tweet_count_help: How many tweets do you want to display?
18
+ visible: Visible?
19
+ visible_yes: Yes
20
+ visible_no: No
@@ -0,0 +1,19 @@
1
+ Refinery::Core::Engine.routes.draw do
2
+ namespace :tweets, :path => '' do
3
+ # get '/contact', :to => 'inquiries#new', :as => 'new_inquiry'
4
+
5
+ # resources :contact,
6
+ # :only => :create,
7
+ # :as => :inquiries,
8
+ # :controller => 'inquiries' do
9
+ # get :thank_you, :on => :collection
10
+ # end
11
+
12
+ namespace :admin, :path => 'refinery' do
13
+ resource :twitter_account
14
+ # scope :path => 'tweets' do
15
+ # resources :settings, :only => [:edit, :update]
16
+ # end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ class CreateTwitterAccounts < ActiveRecord::Migration
2
+ def up
3
+ unless ::Refinery::Tweets::TwitterAccount.table_exists?
4
+ create_table :refinery_tweets_twitter_accounts, :force => true do |t|
5
+ t.string :username
6
+ t.integer :tweet_count, :default => 5
7
+ t.string :widget_id
8
+ t.boolean :visible, :default => true
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
13
+
14
+ def down
15
+ drop_table ::Refinery::Tweets::TwitterAccount.table_name
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # Refinery::Tweets.configure do |config|
2
+
3
+ # Uncomment this line if you don't want to fallback to
4
+ # a jQuery list when there is no widget_id on the account
5
+ #
6
+ # config.fallback_to_jquery_tweet_list = false
7
+
8
+ # Uncomment this line if you don't want to use the
9
+ # Twitter widget, the jQuery implementation will be used
10
+ #
11
+ # config.use_twitter_widget = false
12
+
13
+ # end
@@ -0,0 +1,25 @@
1
+ module Refinery
2
+ class TweetsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_tweets_initializer
6
+ template 'config/initializers/refinery/tweets.rb.erb', File.join(destination_root, 'config', 'initializers', 'refinery', 'tweets.rb')
7
+ end
8
+
9
+ def rake_db
10
+ rake("refinery_tweets:install:migrations")
11
+ # rake("refinery_settings:install:migrations")
12
+ end
13
+
14
+ def append_load_seed_data
15
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
16
+ append_file 'db/seeds.rb', :verbose => true do
17
+ <<-EOH
18
+
19
+ # Added by Refinery CMS Tweets engine
20
+ Refinery::Tweets::Engine.load_seed
21
+ EOH
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'refinerycms-core'
2
+
3
+ module Refinery
4
+ autoload :TweetsGenerator, 'generators/refinery/tweets/tweets_generator'
5
+ module Tweets
6
+ require 'refinery/tweets/engine'
7
+ require 'refinery/tweets/configuration'
8
+
9
+ autoload :Version, 'refinery/tweets/version'
10
+
11
+ class << self
12
+ attr_writer :root
13
+
14
+ def root
15
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
16
+ end
17
+
18
+ def factory_paths
19
+ @factory_paths ||= [ root.join("spec/factories").to_s ]
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,11 @@
1
+ module Refinery
2
+ module Tweets
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :fallback_to_jquery_tweet_list
6
+ config_accessor :use_twitter_widget
7
+
8
+ self.fallback_to_jquery_tweet_list = true
9
+ self.use_twitter_widget = true
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module Refinery
2
+ module Tweets
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+
6
+ isolate_namespace Refinery::Tweets
7
+
8
+ initializer 'load helper' do |app|
9
+ ActiveSupport.on_load :action_controller do
10
+ helper Refinery::Tweets::TweetsHelper
11
+ end
12
+ end
13
+
14
+ initializer "init plugin" do
15
+ Refinery::Plugin.register do |plugin|
16
+ plugin.pathname = root
17
+ plugin.name = "refinerycms_tweets"
18
+ plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.tweets_admin_twitter_account_path }
19
+ plugin.menu_match = %r{refinery/tweets(/.+?)?$}
20
+ plugin.activity = {
21
+ :class_name => :'refinery/tweets/twitter_account',
22
+ :title => 'name',
23
+ :url_prefix => nil,
24
+ :url => 'refinery.tweets_admin_twitter_account_path'
25
+ }
26
+ end
27
+ end
28
+
29
+ config.after_initialize do
30
+ Refinery.register_engine(Refinery::Tweets)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Refinery
2
+ module Tweets
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/tweets'
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright 2013 Chris Holmes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'refinery/tweets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "refinerycms-tweets"
8
+ spec.version = Refinery::Tweets::VERSION
9
+ spec.authors = ["Chris Holmes"]
10
+ spec.email = ["tochrisholmes@gmail.com"]
11
+ spec.description = %q{A Refinery CMS engine to add Twitter functionality.}
12
+ spec.summary = %q{Tweets allows you add a Twitter feed to your site in seconds.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :twitter_account, :class => Refinery::Tweets::TwitterAccount do
3
+ username "twitter"
4
+ tweet_count 8
5
+ widget_id "123456789"
6
+ visible true
7
+ end
8
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ module Tweets
5
+ describe TwitterAccount do
6
+ describe "validations" do
7
+ subject do
8
+ Factory.build(:twitter_account,
9
+ :username => "twitter",
10
+ :tweet_count => "5")
11
+ end
12
+
13
+ it { should be_valid }
14
+ its(:errors) { should be_empty }
15
+ its(:username) { should == "twitter" }
16
+ its(:tweet_count) { should == 5 }
17
+ its(:visible) { should == true }
18
+ end
19
+
20
+ describe "account settings" do
21
+
22
+ before(:each) do
23
+ Rails.cache.clear
24
+ end
25
+
26
+ it "stores the settings in the rails cache" do
27
+ Rails.cache.read('refinery-twitter-account-settings').should be_nil
28
+ twitter_account = FactoryGirl.create(:twitter_account)
29
+
30
+ Rails.cache.read('refinery-twitter-account-settings').should == settings_hash(twitter_account)
31
+ end
32
+
33
+ it "reads the settings from the rails cache" do
34
+ twitter_account = FactoryGirl.create(:twitter_account)
35
+
36
+ TwitterAccount.account_settings.should == settings_hash(twitter_account)
37
+ end
38
+
39
+ it "updates the cache when the settings are changed" do
40
+ twitter_account = FactoryGirl.create(:twitter_account)
41
+
42
+ TwitterAccount.account_settings.should == settings_hash(twitter_account)
43
+ TwitterAccount.account_settings["username"].should == "twitter"
44
+
45
+ twitter_account.update_attribute(:username, "new_username")
46
+
47
+ TwitterAccount.account_settings.should == settings_hash(twitter_account)
48
+ TwitterAccount.account_settings["username"].should == "new_username"
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Tweets
5
+ module Admin
6
+ describe TwitterAccount do
7
+ refinery_login_with :refinery_user
8
+
9
+ let!(:twitter_account) do
10
+ Factory(:twitter_account, :username => "Chris Holmes",
11
+ :tweet_count => 5,
12
+ :widget_id => "123456789",
13
+ :visible => true)
14
+ end
15
+
16
+ context "when no account" do
17
+ before(:each) { Refinery::Tweets::TwitterAccount.destroy_all }
18
+
19
+ context "twitter account" do
20
+ it "shows message" do
21
+ visit refinery.tweets_admin_twitter_account_path
22
+
23
+ page.should have_content("You don't have a Twitter account listed")
24
+ end
25
+
26
+ it "has add account link" do
27
+ visit refinery.tweets_admin_twitter_account_path
28
+
29
+ page.should have_link('Add a Twitter account', href: refinery.new_tweets_admin_twitter_account_path)
30
+ end
31
+ end
32
+ end
33
+
34
+ context "when account" do
35
+ it "does not have link to add account" do
36
+ visit refinery.tweets_admin_twitter_account_path
37
+
38
+ page.should_not have_content("You don't have a Twitter account listed")
39
+ page.should_not have_link('Add a Twitter account', href: refinery.new_tweets_admin_twitter_account_path)
40
+ end
41
+ end
42
+
43
+ describe "show" do
44
+ it "has account details" do
45
+ visit refinery.tweets_admin_twitter_account_path
46
+
47
+ page.should have_content("Your Twitter Account")
48
+ page.should have_content("Username")
49
+ page.should have_content("Number of tweets")
50
+ page.should have_content("Visible")
51
+ end
52
+
53
+ it "has edit link" do
54
+ visit refinery.tweets_admin_twitter_account_path
55
+
56
+ page.should have_link('Edit Twitter account', href: refinery.edit_tweets_admin_twitter_account_path)
57
+ end
58
+
59
+ it "has delete link" do
60
+ visit refinery.tweets_admin_twitter_account_path
61
+
62
+ page.should have_link('Delete Twitter account', href: refinery.tweets_admin_twitter_account_path)
63
+ end
64
+ end
65
+
66
+ describe "destroy" do
67
+ it "removes account" do
68
+ visit refinery.tweets_admin_twitter_account_path
69
+
70
+ click_link "Delete Twitter account"
71
+
72
+ page.should have_content("You don't have a Twitter account listed")
73
+ end
74
+
75
+ it "clears the cached settings" do
76
+ visit refinery.tweets_admin_twitter_account_path
77
+
78
+ click_link "Delete Twitter account"
79
+
80
+ Rails.cache.read('refinery-twitter-account-settings').should == nil
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+
3
+ # Configure Rails Environment
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ require File.expand_path("../dummy/config/environment", __FILE__)
7
+
8
+ require 'rspec/rails'
9
+ require 'capybara/rspec'
10
+ require 'factory_girl_rails'
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.filter_run :focus => true
18
+ config.run_all_when_everything_filtered = true
19
+ end
20
+
21
+ # Requires supporting files with custom matchers and macros, etc,
22
+ # in ./support/ and its subdirectories including factories.
23
+ ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
24
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
25
+ }.flatten.sort.each do |support_file|
26
+ require support_file
27
+ end
28
+
29
+ def settings_hash(twitter_account)
30
+ { "username" => twitter_account.username,
31
+ "tweet_count" => twitter_account.tweet_count,
32
+ "visible" => twitter_account.visible,
33
+ "widget_id" => twitter_account.widget_id
34
+ }
35
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc "Run specs"
4
+ RSpec::Core::RakeTask.new
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-tweets
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Holmes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A Refinery CMS engine to add Twitter functionality.
47
+ email:
48
+ - tochrisholmes@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - app/controllers/refinery/tweets/admin/twitter_accounts_controller.rb
59
+ - app/helpers/refinery/tweets/tweets_helper.rb
60
+ - app/models/refinery/tweets/twitter_account.rb
61
+ - app/views/refinery/tweets/admin/twitter_accounts/_form.html.erb
62
+ - app/views/refinery/tweets/admin/twitter_accounts/_submenu.html.erb
63
+ - app/views/refinery/tweets/admin/twitter_accounts/edit.html.erb
64
+ - app/views/refinery/tweets/admin/twitter_accounts/new.html.erb
65
+ - app/views/refinery/tweets/admin/twitter_accounts/show.html.erb
66
+ - config/locales/en.yml
67
+ - config/routes.rb
68
+ - db/migrate/20101208082999_create_twitter_accounts.rb
69
+ - lib/generators/refinery/tweets/templates/config/initializers/refinery/tweets.rb.erb
70
+ - lib/generators/refinery/tweets/tweets_generator.rb
71
+ - lib/refinery/tweets.rb
72
+ - lib/refinery/tweets/configuration.rb
73
+ - lib/refinery/tweets/engine.rb
74
+ - lib/refinery/tweets/version.rb
75
+ - lib/refinerycms-tweets.rb
76
+ - licence.md
77
+ - refinerycms-tweets.gemspec
78
+ - spec/factories/twitter_account.rb
79
+ - spec/models/refinery/tweets/twitter_account_spec.rb
80
+ - spec/requests/refinery/tweets/admin/tweets_spec.rb
81
+ - spec/spec_helper.rb
82
+ - tasks/rspec.rake
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Tweets allows you add a Twitter feed to your site in seconds.
108
+ test_files:
109
+ - spec/factories/twitter_account.rb
110
+ - spec/models/refinery/tweets/twitter_account_spec.rb
111
+ - spec/requests/refinery/tweets/admin/tweets_spec.rb
112
+ - spec/spec_helper.rb