acts_as_word_cloud 0.0.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.
Files changed (68) hide show
  1. data/.DS_Store +0 -0
  2. data/.document +5 -0
  3. data/.gitignore_new +7 -0
  4. data/.rspec +1 -0
  5. data/CHANGELOG +3 -0
  6. data/Gemfile +22 -0
  7. data/Gemfile.lock +130 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.rdoc +122 -0
  10. data/Rakefile +52 -0
  11. data/VERSION +1 -0
  12. data/acts_as_word_cloud.gemspec +127 -0
  13. data/features/acts_as_word_cloud.feature +9 -0
  14. data/features/step_definitions/acts_as_word_cloud_steps.rb +0 -0
  15. data/features/support/env.rb +13 -0
  16. data/lib/acts_as_word_cloud/config.rb +31 -0
  17. data/lib/acts_as_word_cloud/engine.rb +4 -0
  18. data/lib/acts_as_word_cloud/railtie.rb +12 -0
  19. data/lib/acts_as_word_cloud/word_cloud.rb +227 -0
  20. data/lib/acts_as_word_cloud.rb +2 -0
  21. data/lib/generators/acts_as_word_cloud/install_generator.rb +23 -0
  22. data/lib/generators/acts_as_word_cloud/templates/config.rb +7 -0
  23. data/lib/model_methods_helper.rb +87 -0
  24. data/spec/acts_as_word_cloud_spec.rb +109 -0
  25. data/spec/dummy/README.rdoc +261 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/mailers/.gitkeep +0 -0
  32. data/spec/dummy/app/models/.gitkeep +0 -0
  33. data/spec/dummy/app/models/article.rb +9 -0
  34. data/spec/dummy/app/models/author.rb +7 -0
  35. data/spec/dummy/app/models/following.rb +5 -0
  36. data/spec/dummy/app/models/publisher.rb +7 -0
  37. data/spec/dummy/app/models/reader.rb +7 -0
  38. data/spec/dummy/app/models/site.rb +8 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  40. data/spec/dummy/config/application.rb +65 -0
  41. data/spec/dummy/config/boot.rb +10 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +37 -0
  45. data/spec/dummy/config/environments/production.rb +67 -0
  46. data/spec/dummy/config/environments/test.rb +37 -0
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/spec/dummy/config/initializers/inflections.rb +15 -0
  49. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  50. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  51. data/spec/dummy/config/initializers/session_store.rb +8 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +5 -0
  54. data/spec/dummy/config/routes.rb +58 -0
  55. data/spec/dummy/config.ru +4 -0
  56. data/spec/dummy/db/migrate/20121107162154_create_system.rb +64 -0
  57. data/spec/dummy/db/schema.rb +81 -0
  58. data/spec/dummy/features/support/blueprints.rb +57 -0
  59. data/spec/dummy/lib/assets/.gitkeep +0 -0
  60. data/spec/dummy/lib/model_methods_helper.rb +87 -0
  61. data/spec/dummy/log/.gitkeep +0 -0
  62. data/spec/dummy/public/404.html +26 -0
  63. data/spec/dummy/public/422.html +26 -0
  64. data/spec/dummy/public/500.html +25 -0
  65. data/spec/dummy/public/favicon.ico +0 -0
  66. data/spec/dummy/script/rails +6 -0
  67. data/spec/spec_helper.rb +21 -0
  68. metadata +211 -0
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '493d8c57c3dd0d9e0ec3f93a2ffc5559968d335e4460be98650df1e7b6e0089f8e494702c22250a43c56cff5073a75745a69a6297977a2650b922e46ba6c1f3e'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => 'welcome#index'
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id))(.:format)'
58
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,64 @@
1
+ class CreateSystem < ActiveRecord::Migration
2
+ def change
3
+ create_table :articles do |t|
4
+ t.integer :author_id
5
+ t.integer :publisher_id
6
+ t.integer :site_id
7
+ t.string :title
8
+ t.string :genre
9
+ t.text :content
10
+
11
+ t.timestamps
12
+ end
13
+ add_index :articles, :author_id
14
+ add_index :articles, :publisher_id
15
+ add_index :articles, :site_id
16
+
17
+ create_table :authors do |t|
18
+ t.integer :publisher_id
19
+ t.integer :site_id
20
+ t.string :name
21
+ t.string :genre
22
+ t.integer :age
23
+
24
+ t.timestamps
25
+ end
26
+ add_index :authors, :publisher_id
27
+ add_index :authors, :site_id
28
+
29
+ create_table :publishers do |t|
30
+ t.string :name
31
+ t.string :location
32
+
33
+ t.timestamps
34
+ end
35
+
36
+ create_table :readers do |t|
37
+ t.integer :site_id
38
+ t.string :username
39
+ t.integer :age
40
+
41
+ t.timestamps
42
+ end
43
+ add_index :readers, :site_id
44
+
45
+ create_table :followings do |t|
46
+ t.string :special_name
47
+ t.integer :article_id
48
+ t.integer :reader_id
49
+ end
50
+ add_index :followings, :article_id
51
+ add_index :followings, :reader_id
52
+
53
+ create_table :sites do |t|
54
+ t.integer :publisher_id
55
+ t.string :name
56
+ t.string :domain
57
+ t.string :genre
58
+
59
+ t.timestamps
60
+ end
61
+ add_index :sites, :publisher_id
62
+
63
+ end
64
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20121107162154) do
15
+
16
+ create_table "articles", :force => true do |t|
17
+ t.integer "author_id"
18
+ t.integer "publisher_id"
19
+ t.integer "site_id"
20
+ t.string "title"
21
+ t.string "genre"
22
+ t.text "content"
23
+ t.datetime "created_at", :null => false
24
+ t.datetime "updated_at", :null => false
25
+ end
26
+
27
+ add_index "articles", ["author_id"], :name => "index_articles_on_author_id"
28
+ add_index "articles", ["publisher_id"], :name => "index_articles_on_publisher_id"
29
+ add_index "articles", ["site_id"], :name => "index_articles_on_site_id"
30
+
31
+ create_table "authors", :force => true do |t|
32
+ t.integer "publisher_id"
33
+ t.integer "site_id"
34
+ t.string "name"
35
+ t.string "genre"
36
+ t.integer "age"
37
+ t.datetime "created_at", :null => false
38
+ t.datetime "updated_at", :null => false
39
+ end
40
+
41
+ add_index "authors", ["publisher_id"], :name => "index_authors_on_publisher_id"
42
+ add_index "authors", ["site_id"], :name => "index_authors_on_site_id"
43
+
44
+ create_table "followings", :force => true do |t|
45
+ t.string "special_name"
46
+ t.integer "article_id"
47
+ t.integer "reader_id"
48
+ end
49
+
50
+ add_index "followings", ["article_id"], :name => "index_followings_on_article_id"
51
+ add_index "followings", ["reader_id"], :name => "index_followings_on_reader_id"
52
+
53
+ create_table "publishers", :force => true do |t|
54
+ t.string "name"
55
+ t.string "location"
56
+ t.datetime "created_at", :null => false
57
+ t.datetime "updated_at", :null => false
58
+ end
59
+
60
+ create_table "readers", :force => true do |t|
61
+ t.integer "site_id"
62
+ t.string "username"
63
+ t.integer "age"
64
+ t.datetime "created_at", :null => false
65
+ t.datetime "updated_at", :null => false
66
+ end
67
+
68
+ add_index "readers", ["site_id"], :name => "index_readers_on_site_id"
69
+
70
+ create_table "sites", :force => true do |t|
71
+ t.integer "publisher_id"
72
+ t.string "name"
73
+ t.string "domain"
74
+ t.string "genre"
75
+ t.datetime "created_at", :null => false
76
+ t.datetime "updated_at", :null => false
77
+ end
78
+
79
+ add_index "sites", ["publisher_id"], :name => "index_sites_on_publisher_id"
80
+
81
+ end
@@ -0,0 +1,57 @@
1
+ require 'machinist/active_record'
2
+ require 'faker'
3
+
4
+ def generate_age
5
+ rand(60)+15
6
+ end
7
+
8
+ def generate_text
9
+ Faker::Lorem.words(20).join(' ')
10
+ end
11
+
12
+ def generate_tiny_text
13
+ Faker::Lorem.words(3).join(' ')
14
+ end
15
+
16
+ Article.blueprint do
17
+ author = Author.make
18
+ author_id { author.id }
19
+ publisher_id { author.publisher.id }
20
+ site_id { author.site.id }
21
+ title { generate_tiny_text }
22
+ genre { generate_tiny_text }
23
+ content { generate_text }
24
+ end
25
+
26
+ Author.blueprint do
27
+ site = Site.make
28
+ site_id { site.id }
29
+ publisher_id { site.publisher.id }
30
+ name { generate_tiny_text }
31
+ genre { generate_tiny_text }
32
+ age { generate_age }
33
+ end
34
+
35
+ Publisher.blueprint do
36
+ name { generate_tiny_text }
37
+ location { generate_tiny_text }
38
+ end
39
+
40
+ Following.blueprint do
41
+ special_name { generate_tiny_text }
42
+ article_id { Article.make }
43
+ reader_id { Reader.make }
44
+ end
45
+
46
+ Reader.blueprint do
47
+ site_id { Site.make }
48
+ username { generate_tiny_text }
49
+ age { generate_age }
50
+ end
51
+
52
+ Site.blueprint do
53
+ publisher_id { Publisher.make }
54
+ name { generate_tiny_text }
55
+ domain { generate_tiny_text }
56
+ genre { generate_tiny_text }
57
+ end
File without changes
@@ -0,0 +1,87 @@
1
+ require 'find'
2
+ class ModelMethodsHelper
3
+
4
+ # finds or makes a model based on the given attributes
5
+ # @param [Constant] model_name The name of the model
6
+ # @param [Hash] attributes The attributes to find the model or add to the new one
7
+ def self.find_or_make_by_attributes(model_name, attributes)
8
+ instances = model_name.where(attributes)
9
+ if instances.empty?
10
+ return model_name.make(attributes)
11
+ else
12
+ return instances.first
13
+ end
14
+ end
15
+
16
+ # Uses the descendants_of method to determine the model structure
17
+ # Then tableizes and converts to symbol
18
+ #
19
+ # Load all models must be run for accurate descendants list
20
+ # it is now being called every time this method is called
21
+ # for now it works because this is only called one time when the authorization config is loaded on initialize
22
+ # if this ever changes, this code may need to be update (2-15-2012)
23
+ #
24
+ # @return [Array] Array with file names underscored and pluralized in the format [:users, :case_placements, :roles, :job_locations, ... ]
25
+ def self.get_model_symbol_array
26
+ # Old method:
27
+ # Major redesign of this method that finds namespaced models
28
+ # Finds all files in the given folder, tries to find the ruby files
29
+ # Then processes the names to get the names we need for the code
30
+ #
31
+ # @return [Array] Array with file names underscored and pluralized in the format [:users, :case_placements, :roles, :job_locations, ... ]
32
+ #model_array = []
33
+ #Find.find("#{Rails.root.to_s}/app/models") do |model_path|
34
+ # if model_path.match(/\.rb$/)
35
+ # model_path = model_path.gsub("#{Rails.root.to_s}/app/models/", "")
36
+ # model_path = model_path.gsub("/","_")
37
+ # model_path = model_path.gsub(/\.rb$/, "")
38
+ # model_array.push model_path.pluralize.to_sym
39
+ # end
40
+ #end
41
+ #return model_array
42
+
43
+ # new method
44
+ self.load_all_models
45
+ # returns the table name if there is one or tableizes the model name if not
46
+ # our permissions system generally uses table names for model permissions
47
+ return self.descendants_of(ActiveRecord::Base).map{ |m| m.abstract_class ? m.to_s.tableize.to_sym : m.table_name.to_sym }
48
+ end
49
+
50
+ # Requires all models so that they are visible in the object space
51
+ # This is only necessary when we are not caching classes
52
+ def self.load_all_models
53
+ if !::Rails.application.config.cache_classes
54
+ Dir[Rails.root.join("app/models/**/*.rb")].each {|f| require f}
55
+ end
56
+ end
57
+
58
+ # Return a list of descendants of the given model.
59
+ #
60
+ # If direct is set to true, only return immediate descendants
61
+ # The load_all_models must be called before this is called or the result may not be correct
62
+ #
63
+ # @param [Constant] parent_class The parent class to look for descendants for
64
+ # @param [Boolean] direct Whether to look for all descendants or immediate descendants
65
+ # @return [Array] An array of class constants that satisfy the conditions of the parameters
66
+ def self.descendants_of(parent_class, direct = false)
67
+ classes = []
68
+ ObjectSpace.each_object(::Class).each do |klass|
69
+ if direct
70
+ classes << klass if klass.superclass == parent_class
71
+ else
72
+ classes << klass if klass < parent_class
73
+ end
74
+ end
75
+ return classes
76
+ end
77
+
78
+ # Convenience method to return the results of descendants_of with direct set to true
79
+ #
80
+ # The load_all_models must be called before this is called or the result may not be correct
81
+ #
82
+ # @param [Constant] parent_class The parent class to look for descendants for
83
+ # @return [Array] An array of class constants that satisfy the conditions of the parameters
84
+ def self.direct_descendants_of(parent_class)
85
+ return self.descendants_of(parent_class, true)
86
+ end
87
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ ENV["RAILS_ENV"] = 'test'
5
+ require File.expand_path("../dummy/config/environment", __FILE__)
6
+ require File.expand_path("../dummy/features/support/blueprints", __FILE__)
7
+ require File.expand_path("../dummy/lib/model_methods_helper", __FILE__)
8
+
9
+ require 'rspec'
10
+ require 'acts_as_word_cloud'
11
+
12
+
13
+ # Requires supporting files with custom matchers and macros, etc,
14
+ # in ./support/ and its subdirectories.
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+
19
+ config.mock_with :rspec
20
+
21
+ end