chameleon 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.rdoc +8 -28
  2. data/app/controllers/widgets_controller.rb +8 -2
  3. data/app/models/widget.rb +5 -0
  4. data/app/views/widgets/line.xml.erb +15 -0
  5. data/app/views/widgets/number_and_secondary.xml.erb +2 -2
  6. data/app/views/widgets/pie.xml.erb +10 -0
  7. metadata +7 -48
  8. data/test/chameleon_test.rb +0 -7
  9. data/test/dummy/Rakefile +0 -7
  10. data/test/dummy/app/controllers/application_controller.rb +0 -3
  11. data/test/dummy/app/helpers/application_helper.rb +0 -2
  12. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  13. data/test/dummy/app/widgets/test_widget.rb +0 -7
  14. data/test/dummy/app/widgets/test_widget2.rb +0 -8
  15. data/test/dummy/config.ru +0 -4
  16. data/test/dummy/config/application.rb +0 -45
  17. data/test/dummy/config/boot.rb +0 -10
  18. data/test/dummy/config/database.yml +0 -22
  19. data/test/dummy/config/environment.rb +0 -5
  20. data/test/dummy/config/environments/development.rb +0 -26
  21. data/test/dummy/config/environments/production.rb +0 -49
  22. data/test/dummy/config/environments/test.rb +0 -35
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  24. data/test/dummy/config/initializers/inflections.rb +0 -10
  25. data/test/dummy/config/initializers/mime_types.rb +0 -5
  26. data/test/dummy/config/initializers/secret_token.rb +0 -7
  27. data/test/dummy/config/initializers/session_store.rb +0 -8
  28. data/test/dummy/config/locales/en.yml +0 -5
  29. data/test/dummy/config/routes.rb +0 -58
  30. data/test/dummy/db/test.sqlite3 +0 -0
  31. data/test/dummy/log/development.log +0 -2
  32. data/test/dummy/log/production.log +0 -0
  33. data/test/dummy/log/server.log +0 -0
  34. data/test/dummy/log/test.log +0 -334
  35. data/test/dummy/public/404.html +0 -26
  36. data/test/dummy/public/422.html +0 -26
  37. data/test/dummy/public/500.html +0 -26
  38. data/test/dummy/public/favicon.ico +0 -0
  39. data/test/dummy/public/javascripts/application.js +0 -2
  40. data/test/dummy/public/javascripts/controls.js +0 -965
  41. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  42. data/test/dummy/public/javascripts/effects.js +0 -1123
  43. data/test/dummy/public/javascripts/prototype.js +0 -6001
  44. data/test/dummy/public/javascripts/rails.js +0 -175
  45. data/test/dummy/script/rails +0 -6
  46. data/test/functional/widgets_test.rb +0 -31
  47. data/test/integration/navigation_test.rb +0 -7
  48. data/test/support/integration_case.rb +0 -5
  49. data/test/test_helper.rb +0 -22
  50. data/test/unit/widget_test.rb +0 -13
@@ -12,7 +12,7 @@ This only works for Rails 3 apps.
12
12
 
13
13
  This provides a generator to build widgets using a basic DSL syntax to describe the data to be exposed, and the settings for it to be exposed under, and also includes the controller/routing necessary to provide an endpoint for Geckoboard to retrieve the data to display on your dashboard.
14
14
 
15
- Currently it supports just the "number and optional secondary stat" widget type, with more widget types to follow shortly.
15
+ Currently it supports the "number and optional secondary stat", "line" and "pie" widget types.
16
16
 
17
17
  == SYNOPSIS:
18
18
 
@@ -37,42 +37,22 @@ This will generate something similar to the following in "app/widgets/users_widg
37
37
  end
38
38
  end
39
39
 
40
- To implement your widget, you simply need to alter it to return the required data - for a "number_and_secondary" type of widget, it requires an array containing two values, the first being the current value, and the last being the value to compare it to (such as user count as of yesterday, for example):
40
+ To implement your widget, you simply need to alter it to return the required data - for a "number_and_secondary" type of widget, it requires a hash containing a :value, and optionally, a :previous value to compare it to (such as user count as of yesterday, for example):
41
41
 
42
42
  widget :users do
43
43
  key "3618c90ec02d5a57061ad7b78afcbb050e50b608"
44
44
  type "number_and_secondary"
45
45
  data do
46
- [User.count, User.count(:conditions => "created_at < '#{1.day.ago.to_s(:db)}'")]
46
+ {
47
+ :value => User.count,
48
+ :previous => User.count(:conditions => "created_at < '#{1.day.ago.to_s(:db)}'")
49
+ }
47
50
  end
48
51
  end
49
52
 
50
- You can then point Geckoboard at your widget, http://myapp/widgets/users?key=3618c90ec02d5a57061ad7b78afcbb050e50b608, and Geckoboard will then show the current user count, as well as the percentage difference compared to a day ago. You can optionally just return a single value too, if you don't want the secondary stat.
53
+ You can then point Geckoboard at your widget, http://myapp/widgets/users?key=3618c90ec02d5a57061ad7b78afcbb050e50b608, and Geckoboard will then show the current user count, as well as the percentage difference compared to a day ago.
51
54
 
52
- By default the widgets are secured by the key which is autogenerated within the widget - this has to be passed in via the querystring for the widget to function, as seen above. You can change this value to anything you consider secure, and if you require a parameter other than :key to be used for this security check, you can define the parameter as such:
53
-
54
- widget :users do
55
- key "my_updated_key"
56
- key_parameter :token
57
- type "number_and_secondary"
58
- data do
59
- [User.count, User.count(:conditions => "created_at < '#{1.day.ago.to_s(:db)}'")]
60
- end
61
- end
62
-
63
- This will now expect the key to be passed in as the :token parameter, for example http://myapp/widgets/users?token=my_updated_key. For data that is acceptable to be publically exposed, you can exclude the key and set the widget as public as follows:
64
-
65
- widget :users do
66
- public true
67
- type "number_and_secondary"
68
- data do
69
- [User.count, User.count(:conditions => "created_at < '#{1.day.ago.to_s(:db)}'")]
70
- end
71
- end
72
-
73
- This will now be accessible simply at http://myapp/widgets/users.
74
-
75
- Full documentation on the different widget types and data will follow once the other widget types are implemented, but this basic syntax should provide an easy way to expose data from your Rails 3 application to Geckoboard quickly and easily.
55
+ More documentation on the settings available for the widgets, as well as the different types of widgets, is available on the wiki (http://github.com/ejdraper/chameleon/wiki).
76
56
 
77
57
  == REQUIREMENTS:
78
58
 
@@ -4,7 +4,7 @@ class WidgetsController < ApplicationController
4
4
  skip_before_filter :verify_authenticity_token
5
5
 
6
6
  def show
7
- @data = @widget.data.call
7
+ @data = @widget.data.call(@auth)
8
8
  render "#{@widget.type}.xml"
9
9
  end
10
10
 
@@ -15,6 +15,12 @@ class WidgetsController < ApplicationController
15
15
  end
16
16
 
17
17
  def validate_key
18
- raise "Invalid key!" if !@widget.public && (params[@widget.key_parameter].blank? || params[@widget.key_parameter] != @widget.key)
18
+ return if @widget.public
19
+ if @widget.auth
20
+ @auth = @widget.auth.call(self, request, params)
21
+ raise "Invalid authentication!" if !@auth
22
+ else
23
+ raise "Invalid key!" if params[@widget.key_parameter] != @widget.key
24
+ end
19
25
  end
20
26
  end
@@ -30,6 +30,11 @@ class Widget
30
30
  @key_parameter || :key
31
31
  end
32
32
 
33
+ def auth(&block)
34
+ @auth = block if block_given?
35
+ @auth
36
+ end
37
+
33
38
  def type(value = nil)
34
39
  @type = value unless value.nil?
35
40
  @type
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <root>
3
+ <% @data[:items].each do |item| %>
4
+ <item><%= item %></item>
5
+ <% end %>
6
+ <settings>
7
+ <% @data[:x_axis].each do |x| %>
8
+ <axisx><%= x %></axisx>
9
+ <% end %>
10
+ <% @data[:y_axis].each do |y| %>
11
+ <axisy><%= y %></axisy>
12
+ <% end %>
13
+ <colour><%= @data[:colour] || "ff9900" %></colour>
14
+ </settings>
15
+ </root>
@@ -1,11 +1,11 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <root>
3
3
  <item>
4
- <value><%= @data.is_a?(Array) ? @data.first : @data %></value>
4
+ <value><%= @data[:value] %></value>
5
5
  <text></text>
6
6
  </item>
7
7
  <item>
8
- <value><%= @data.is_a?(Array) && @data.length == 2 ? @data.last : nil %></value>
8
+ <value><%= @data[:previous] %></value>
9
9
  <text></text>
10
10
  </item>
11
11
  </root>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <root>
3
+ <% @data.each do |item| %>
4
+ <item>
5
+ <value><%= item[:value] %></value>
6
+ <label><%= item[:label] %></label>
7
+ <colour><%= item[:colour] %></colour>
8
+ </item>
9
+ <% end %>
10
+ </root>
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Elliott Draper
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-22 00:00:00 +00:00
17
+ date: 2011-01-04 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,51 +45,10 @@ files:
45
45
  - README.rdoc
46
46
  - app/controllers/widgets_controller.rb
47
47
  - app/models/widget.rb
48
+ - app/views/widgets/line.xml.erb
48
49
  - app/views/widgets/number_and_secondary.xml.erb
50
+ - app/views/widgets/pie.xml.erb
49
51
  - config/routes.rb
50
- - test/chameleon_test.rb
51
- - test/dummy/app/controllers/application_controller.rb
52
- - test/dummy/app/helpers/application_helper.rb
53
- - test/dummy/app/views/layouts/application.html.erb
54
- - test/dummy/app/widgets/test_widget.rb
55
- - test/dummy/app/widgets/test_widget2.rb
56
- - test/dummy/config/application.rb
57
- - test/dummy/config/boot.rb
58
- - test/dummy/config/database.yml
59
- - test/dummy/config/environment.rb
60
- - test/dummy/config/environments/development.rb
61
- - test/dummy/config/environments/production.rb
62
- - test/dummy/config/environments/test.rb
63
- - test/dummy/config/initializers/backtrace_silencers.rb
64
- - test/dummy/config/initializers/inflections.rb
65
- - test/dummy/config/initializers/mime_types.rb
66
- - test/dummy/config/initializers/secret_token.rb
67
- - test/dummy/config/initializers/session_store.rb
68
- - test/dummy/config/locales/en.yml
69
- - test/dummy/config/routes.rb
70
- - test/dummy/config.ru
71
- - test/dummy/db/test.sqlite3
72
- - test/dummy/log/development.log
73
- - test/dummy/log/production.log
74
- - test/dummy/log/server.log
75
- - test/dummy/log/test.log
76
- - test/dummy/public/404.html
77
- - test/dummy/public/422.html
78
- - test/dummy/public/500.html
79
- - test/dummy/public/favicon.ico
80
- - test/dummy/public/javascripts/application.js
81
- - test/dummy/public/javascripts/controls.js
82
- - test/dummy/public/javascripts/dragdrop.js
83
- - test/dummy/public/javascripts/effects.js
84
- - test/dummy/public/javascripts/prototype.js
85
- - test/dummy/public/javascripts/rails.js
86
- - test/dummy/Rakefile
87
- - test/dummy/script/rails
88
- - test/functional/widgets_test.rb
89
- - test/integration/navigation_test.rb
90
- - test/support/integration_case.rb
91
- - test/test_helper.rb
92
- - test/unit/widget_test.rb
93
52
  - lib/chameleon.rb
94
53
  - lib/generators/chameleon/widget_generator.rb
95
54
  has_rdoc: true
@@ -107,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
66
  requirements:
108
67
  - - ">="
109
68
  - !ruby/object:Gem::Version
110
- hash: 2506435241547963230
69
+ hash: 2842150292622897971
111
70
  segments:
112
71
  - 0
113
72
  version: "0"
@@ -116,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
75
  requirements:
117
76
  - - ">="
118
77
  - !ruby/object:Gem::Version
119
- hash: 2506435241547963230
78
+ hash: 2842150292622897971
120
79
  segments:
121
80
  - 0
122
81
  version: "0"
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ChameleonTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Chameleon
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- Dummy::Application.load_tasks
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,7 +0,0 @@
1
- widget :test do
2
- key "c6fdeae2af2c327cac35abc2ccacd8619af56821"
3
- type "number_and_secondary"
4
- data do
5
- [1,2]
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- widget :test2 do
2
- key "c6fdeae2af2c327cac35abc2ccacd8619af56821"
3
- key_parameter :token
4
- type "number_and_secondary"
5
- data do
6
- [1,2]
7
- end
8
- end
@@ -1,4 +0,0 @@
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
@@ -1,45 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require "active_model/railtie"
4
- require "active_record/railtie"
5
- require "action_controller/railtie"
6
- require "action_view/railtie"
7
- require "action_mailer/railtie"
8
-
9
- Bundler.require
10
- require "chameleon"
11
-
12
- module Dummy
13
- class Application < Rails::Application
14
- # Settings in config/environments/* take precedence over those specified here.
15
- # Application configuration should go into files in config/initializers
16
- # -- all .rb files in that directory are automatically loaded.
17
-
18
- # Custom directories with classes and modules you want to be autoloadable.
19
- # config.autoload_paths += %W(#{config.root}/extras)
20
-
21
- # Only load the plugins named here, in the order given (default is alphabetical).
22
- # :all can be used as a placeholder for all plugins not explicitly named.
23
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
-
25
- # Activate observers that should always be running.
26
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
-
28
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
- # config.time_zone = 'Central Time (US & Canada)'
31
-
32
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
- # config.i18n.default_locale = :de
35
-
36
- # JavaScript files you want as :defaults (application.js is always included).
37
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
-
39
- # Configure the default encoding used in templates for Ruby 1.9.
40
- config.encoding = "utf-8"
41
-
42
- # Configure sensitive parameters which will be filtered from the log file.
43
- config.filter_parameters += [:password]
44
- end
45
- end
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,22 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
@@ -1,26 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
-
20
- # Print deprecation notices to the Rails logger
21
- config.active_support.deprecation = :log
22
-
23
- # Only use best-standards-support built into browsers
24
- config.action_dispatch.best_standards_support = :builtin
25
- end
26
-
@@ -1,49 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
- config.cache_classes = true
7
-
8
- # Full error reports are disabled and caching is turned on
9
- config.consider_all_requests_local = false
10
- config.action_controller.perform_caching = true
11
-
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
-
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
-
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
20
-
21
- # See everything in the log (default is :info)
22
- # config.log_level = :debug
23
-
24
- # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
26
-
27
- # Use a different cache store in production
28
- # config.cache_store = :mem_cache_store
29
-
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
- # Enable threaded mode
41
- # config.threadsafe!
42
-
43
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
- # the I18n.default_locale when a translation can not be found)
45
- config.i18n.fallbacks = true
46
-
47
- # Send deprecation notices to registered listeners
48
- config.active_support.deprecation = :notify
49
- end