platform 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.rvmrc +2 -0
  2. data/Gemfile.lock +4 -4
  3. data/README.rdoc +0 -3
  4. data/app/assets/javascripts/platform/api_explorer.js +4 -1
  5. data/app/controllers/platform/api/base_controller.rb +39 -20
  6. data/app/models/platform/application.rb +2 -4
  7. data/app/models/platform/developer.rb +4 -2
  8. data/app/models/platform/logged_exception.rb +2 -2
  9. data/app/models/platform/media/media.rb +6 -3
  10. data/app/views/platform/admin/apps/index.html.erb +1 -1
  11. data/app/views/platform/apps/index.html.erb +2 -2
  12. data/app/views/platform/developer/api_explorer/index.html.erb +9 -5
  13. data/app/views/platform/developer/apps/_form.html.erb +4 -2
  14. data/app/views/platform/developer/apps/index.html.erb +6 -4
  15. data/app/views/platform/developer/common/_header.html.erb +0 -1
  16. data/app/views/platform/developer/dashboard/_statistics.html.erb +1 -1
  17. data/app/views/platform/developer/dashboard/index.html.erb +1 -1
  18. data/app/views/platform/developer/help/oauth_mobile.html.erb +5 -3
  19. data/app/views/platform/developer/registration/index.html.erb +8 -123
  20. data/lib/generators/platform/api_generator.rb +74 -0
  21. data/lib/generators/platform/platform_generator.rb +1 -1
  22. data/lib/generators/platform/proxy_generator.rb +1 -2
  23. data/lib/generators/platform/templates/config/platform/config.yml +9 -8
  24. data/lib/generators/platform/templates/config/platform/data/default_applications.yml +1 -23
  25. data/lib/generators/platform/templates/config/platform/data/default_categories.yml +1 -6
  26. data/lib/generators/platform/templates/config/platform/data/default_permissions.yml +16 -0
  27. data/lib/generators/platform/templates/config/platform/site/features.yml +1 -6
  28. data/lib/generators/platform/templates/db/create_platform_tables.rb +36 -47
  29. data/lib/platform/api/proxy/base.rb +4 -0
  30. data/lib/platform/config.rb +12 -16
  31. data/lib/platform/extensions/action_view_extension.rb +13 -1
  32. data/lib/platform/extensions/hash_extension.rb +69 -0
  33. data/lib/platform/railtie.rb +1 -0
  34. data/lib/platform/version.rb +1 -1
  35. data/lib/tasks/platform.rake +1 -0
  36. data/platform.gemspec +0 -1
  37. data/test/dummy/app/assets/images/logo.png +0 -0
  38. data/test/dummy/app/controllers/api/bookmarks_controller.rb +1 -1
  39. data/test/dummy/app/models/bookmark.rb +0 -2
  40. data/test/dummy/app/models/user.rb +1 -2
  41. data/test/dummy/app/views/home/index.html.erb +2 -2
  42. data/test/dummy/app/views/layouts/_footer.html.erb +1 -1
  43. data/test/dummy/app/views/layouts/_header.html.erb +1 -1
  44. data/test/dummy/config/application.rb +0 -1
  45. data/test/dummy/config/environments/development.rb +3 -1
  46. data/test/dummy/config/initializers/platform.rb +3 -0
  47. data/test/dummy/config/platform/api/1/bookmark.yml +2 -2
  48. data/test/dummy/config/platform/config.yml +10 -9
  49. data/test/dummy/config/platform/data/default_applications.yml +4 -23
  50. data/test/dummy/config/platform/data/default_categories.yml +1 -6
  51. data/test/dummy/config/platform/site/features.yml +1 -6
  52. data/test/dummy/config/routes.rb +1 -1
  53. data/test/dummy/config/tr8n/config.yml +2 -2
  54. data/test/dummy/db/migrate/20111004075531_create_platform_tables.rb +1 -1
  55. data/test/dummy/public/developer_agreement.html +123 -0
  56. metadata +52 -46
  57. data/db/migrate/20110602232141_create_platform_tables.rb +0 -262
@@ -48,6 +48,10 @@ module Platform
48
48
  def to_api_hash(opts = {})
49
49
  raise NotImplementedError, 'Must be implemented in descendant class'
50
50
  end
51
+
52
+ def sanitize_api_hash(hash)
53
+ hash.select{|key, value| !value.blank?}
54
+ end
51
55
 
52
56
  def to_api_path(opts = {})
53
57
  "#{Platform::Config.api_scheme}://#{Platform::Config.api_base_url}/#{instance.class.name.underscore}/#{instance.id}"
@@ -89,17 +89,11 @@ module Platform
89
89
  end
90
90
 
91
91
  init_default_categories
92
- init_default_applications
93
92
 
94
93
  puts "Done."
95
94
  end
96
95
 
97
96
  def self.system_user
98
- if user_class_name == "Platform::PlatformUser"
99
- @system_user ||= Platform::PlatformUser.first || Platform::PlatformUser.create(:name => "System User")
100
- return @system_user
101
- end
102
-
103
97
  return nil unless site_info[:system_user_id]
104
98
  @system_user ||= user_class_name.constantize.find_by_id(site_info[:system_user_id])
105
99
  end
@@ -116,16 +110,8 @@ module Platform
116
110
  end
117
111
 
118
112
  default_applications.each do |keyword, description|
119
- category_keywords = description.delete("category_keywords")
120
- icon_path = description.delete("icon_path")
121
- logo_path = description.delete("logo_path")
122
-
123
113
  app = Platform::Application.create(description.merge(:developer => system_developer))
124
- app.store_icon(File.new("#{root}/#{icon_path}", "r")) if icon_path
125
- app.store_logo(File.new("#{root}/#{logo_path}", "r")) if logo_path
126
-
127
114
  puts "Initialized #{app.name}."
128
- app.approve!
129
115
  end
130
116
  end
131
117
 
@@ -158,8 +144,9 @@ module Platform
158
144
  end
159
145
 
160
146
  def self.load_yml(file_path, for_env = env)
161
- yml = YAML.load_file("#{root}#{file_path}")
162
- yml = yml[for_env] unless for_env.nil?
147
+ yml_path = "#{root}#{file_path}"
148
+ yml = YAML.load_file(yml_path)
149
+ yml = yml['defaults'].rmerge(yml[for_env] || {}) unless for_env.nil?
163
150
  HashWithIndifferentAccess.new(yml)
164
151
  end
165
152
 
@@ -191,6 +178,10 @@ module Platform
191
178
  config[:enable_developer_agreement]
192
179
  end
193
180
 
181
+ def self.developer_agreement_path
182
+ config[:developer_agreement_path]
183
+ end
184
+
194
185
  def self.enable_app_statistics?
195
186
  config[:enable_app_statistics]
196
187
  end
@@ -602,6 +593,11 @@ module Platform
602
593
  config[:api_explorer_app_id]
603
594
  end
604
595
 
596
+ def self.api_explorer_app
597
+ return if api_explorer_app_id.blank?
598
+ @api_explorer_app ||= Platform::Application.find_by_id(api_explorer_app_id)
599
+ end
600
+
605
601
  def self.api_explorer_app?
606
602
  !api_explorer_app_id.blank?
607
603
  end
@@ -126,6 +126,18 @@ module Platform
126
126
  end
127
127
  end
128
128
 
129
+ def platform_app_icon_tag(app, options = {})
130
+ options[:style] ||= ""
131
+ options[:style] << "width:16px;height:16px;"
132
+ image_tag(app.icon_url, :style => options[:style])
133
+ end
134
+
135
+ def platform_app_logo_tag(app, options = {})
136
+ options[:style] ||= ""
137
+ options[:style] << "width:75px;height:75px;"
138
+ image_tag(app.logo_url, :style => options[:style])
139
+ end
140
+
129
141
  def platform_user_mugshot_tag(user, options = {})
130
142
  if user and !Platform::Config.user_mugshot(user).blank?
131
143
  img_url = Platform::Config.user_mugshot(user)
@@ -183,7 +195,7 @@ module Platform
183
195
  return platform_when_string_tr("{hours||hour} ago", :hours => (elapsed_seconds / 1.hour).to_i) if elapsed_seconds < 1.day
184
196
  return platform_when_string_tr("Yesterday") if elapsed_seconds < 48.hours
185
197
  return platform_when_string_tr("{days||day} ago", :days => elapsed_seconds.to_i / 1.day) if elapsed_seconds < 14.days
186
- return platform_when_string_tr("{weeks||week} ago", :weeks => (elapsed_seconds / 1.day / 7).to_i) if elapsed_weeks < 4
198
+ return platform_when_string_tr("{weeks||week} ago", :weeks => (elapsed_seconds / 1.day / 7).to_i) if elapsed_seconds < 4.weeks
187
199
  return platform_display_time(time, :monthname_abbr) if Date.today.year == time.year
188
200
  return platform_display_time(time, :monthname_abbr_year)
189
201
  end
@@ -0,0 +1,69 @@
1
+ #
2
+ # = Hash Recursive Merge
3
+ #
4
+ # Merges a Ruby Hash recursively, Also known as deep merge.
5
+ # Recursive version of Hash#merge and Hash#merge!.
6
+ #
7
+ # Category:: Ruby
8
+ # Package:: Hash
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # Copyright:: 2007-2008 The Authors
11
+ # License:: MIT License
12
+ # Link:: http://www.simonecarletti.com/
13
+ # Source:: http://gist.github.com/gists/6391/
14
+
15
+ class Hash
16
+ #
17
+ # Recursive version of Hash#merge!
18
+ #
19
+ # Adds the contents of +other_hash+ to +hsh+,
20
+ # merging entries in +hsh+ with duplicate keys with those from +other_hash+.
21
+ #
22
+ # Compared with Hash#merge!, this method supports nested hashes.
23
+ # When both +hsh+ and +other_hash+ contains an entry with the same key,
24
+ # it merges and returns the values from both arrays.
25
+ #
26
+ # h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
27
+ # h2 = {"b" => 254, "c" => 300, "c" => {"c1" => 16, "c3" => 94}}
28
+ # h1.rmerge!(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
29
+ #
30
+ # Simply using Hash#merge! would return
31
+ #
32
+ # h1.merge!(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
33
+ #
34
+ def rmerge!(other_hash)
35
+ merge!(other_hash) do |key, oldval, newval|
36
+ oldval.class == self.class ? oldval.rmerge!(newval) : newval
37
+ end
38
+ end
39
+
40
+ #
41
+ # Recursive version of Hash#merge
42
+ #
43
+ # Compared with Hash#merge!, this method supports nested hashes.
44
+ # When both +hsh+ and +other_hash+ contains an entry with the same key,
45
+ # it merges and returns the values from both arrays.
46
+ #
47
+ # Compared with Hash#merge, this method provides a different approch
48
+ # for merging nasted hashes.
49
+ # If the value of a given key is an Hash and both +other_hash+ abd +hsh
50
+ # includes the same key, the value is merged instead replaced with
51
+ # +other_hash+ value.
52
+ #
53
+ # h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
54
+ # h2 = {"b" => 254, "c" => 300, "c" => {"c1" => 16, "c3" => 94}}
55
+ # h1.rmerge(h2) #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
56
+ #
57
+ # Simply using Hash#merge would return
58
+ #
59
+ # h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
60
+ #
61
+ def rmerge(other_hash)
62
+ r = {}
63
+ merge(other_hash) do |key, oldval, newval|
64
+ r[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval
65
+ end
66
+ end
67
+
68
+ end
69
+
@@ -35,6 +35,7 @@ require 'pp'
35
35
  end
36
36
 
37
37
  require File.join(File.dirname(__FILE__), 'extensions/object_extension')
38
+ require File.join(File.dirname(__FILE__), 'extensions/hash_extension')
38
39
  require File.join(File.dirname(__FILE__), 'extensions/action_view_extension')
39
40
  require File.join(File.dirname(__FILE__), 'extensions/action_controller_extension')
40
41
 
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Platform
25
- VERSION = "3.1.2"
25
+ VERSION = "3.1.3"
26
26
  end
@@ -26,6 +26,7 @@ namespace :platform do
26
26
  desc "Initializes all of the tables with default data"
27
27
  task :init => :environment do
28
28
  raise "This action is prohibited in this environment" if ['production', 'stage', 'staging'].include?(Rails.env) and env('force') != 'true'
29
+ Tr8n::Config.reset_all!
29
30
  Platform::Config.reset_all!
30
31
  end
31
32
 
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_dependency 'coffee-script', ['>= 0']
31
31
  s.add_dependency 'acts_as_tree', ['>= 0']
32
32
  s.add_dependency 'acts_as_state_machine', ['>= 0']
33
- # s.add_dependency 'rmagick', ['>= 0']
34
33
  s.add_development_dependency 'pry', ['>= 0']
35
34
  s.add_development_dependency 'bundler', ['>= 1.0.0']
36
35
  s.add_development_dependency 'sqlite3', ['>= 0']
@@ -23,7 +23,7 @@ class Api::BookmarksController < Api::BaseController
23
23
  render_response page_model
24
24
  end
25
25
 
26
- def delete
26
+ def destroy
27
27
  ensure_logged_in
28
28
  ensure_post
29
29
  ensure_ownership
@@ -1,7 +1,5 @@
1
1
  class Bookmark < ActiveRecord::Base
2
2
 
3
- has_platform_api_proxy
4
-
5
3
  belongs_to :user
6
4
 
7
5
  end
@@ -3,13 +3,12 @@ class User < ActiveRecord::Base
3
3
  has_one :admin
4
4
  has_many :bookmarks
5
5
 
6
- has_platform_api_proxy
7
-
8
6
  def guest?
9
7
  id.blank?
10
8
  end
11
9
 
12
10
  def admin?
11
+ return true if Rails.env == 'development'
13
12
  not admin.nil?
14
13
  end
15
14
 
@@ -14,7 +14,7 @@
14
14
  <div class="content_bd">
15
15
  <h3><%=tr("If you are trying out Platform functionality, here are some helpful links to get started:")%></h3>
16
16
  <ul style="list-style-type:decimal; margin-left:30px; font-size:14px;">
17
- <li><%= link_to(tr("Register for a developer account"), "/login/register")%></li>
17
+ <li><%= link_to(tr("Register for an account"), "/login/register")%></li>
18
18
  <li><%= link_to(tr("Create a new application"), "/platform/developer/apps")%></li>
19
19
  <li><%= link_to(tr("Explore existing applications"), "/platform/apps")%></li>
20
20
  <li><%= link_to(tr("View your application dashboard"), "/platform/developer/dashboard")%></li>
@@ -31,7 +31,7 @@
31
31
  <%=tr("Drag the link below to your browser's toolbar or add it to your bookmark list:") %>
32
32
  </p>
33
33
  <p>
34
- <a href="javascript:(function(){location.href='http://localhost:3000/api/bookmark/create?bookmarklet=1&title=' + escape(document.title) + '&url='+escape(location.href);})()">Post to Sample Application</a>
34
+ <a href="javascript:(function(){location.href='http://localhost:3000/api/bookmark/create?bookmarklet=1&title=' + escape(document.title) + '&url='+escape(location.href);})()">Post to Bookmarklet</a>
35
35
  </p>
36
36
  <p>
37
37
  <%=tr("When you're surfing the web and find a page that you want to bookmark, just click the \"Post to Sample Application\" button on your toolbar or choose it in your bookmark list.") %>
@@ -7,7 +7,7 @@
7
7
  <li><%=link_to(tr("Credits"), "/platform/developer/help/credits", :class => "quiet")%></li>
8
8
  <li><%=link_to(tr("License"), "/platform/developer/help/license", :class => "quiet")%></li>
9
9
  </ul>
10
- &copy; Copyright 2010-2011 Michael Berkovich
10
+ &copy; Copyright 2010-2011
11
11
  </div>
12
12
 
13
13
  </div>
@@ -12,7 +12,7 @@
12
12
  <li><%= tr8n_language_selector_tag(:lightbox=>false) %></li>
13
13
  </ul>
14
14
  <h1 class="logo">
15
- <%=link_to("Sample Application", "/home", :style=>"text-decorations:none;")%>
15
+ <%=link_to("Bookmarklet", "/home", :style=>"text-decorations:none;")%>
16
16
  </h1>
17
17
  </div>
18
18
  </div>
@@ -9,7 +9,6 @@ require "kaminari"
9
9
  require "platform"
10
10
  require "acts_as_tree"
11
11
  require "acts_as_state_machine"
12
- # require "rmagick"
13
12
 
14
13
  module Dummy
15
14
  class Application < Rails::Application
@@ -4,7 +4,9 @@ Dummy::Application.configure do
4
4
  # In the development environment your application's code is reloaded on
5
5
  # every request. This slows down response time but is perfect for development
6
6
  # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
7
+
8
+ # must be enabled for injectable proxies - TODO: figure out how to unload them
9
+ config.cache_classes = true
8
10
 
9
11
  # Log error messages when you accidentally call methods on nil.
10
12
  config.whiny_nils = true
@@ -0,0 +1,3 @@
1
+ [User, Bookmark, Platform::Application, Platform::Developer].each do |klass|
2
+ klass.has_platform_api_proxy
3
+ end
@@ -70,8 +70,8 @@ bookmark:
70
70
  description: "The bookmark's creation date as a timestamp"
71
71
  type: "Number"
72
72
  status: updated
73
- delete:
74
- path: "bookmark/delete"
73
+ destroy:
74
+ path: "bookmark/destroy"
75
75
  method: POST
76
76
  status: added
77
77
  description: "Removes a bookmark."
@@ -9,16 +9,23 @@
9
9
  # Alternatively, you can overload any of the methods of Platform::Config
10
10
  #############################################################################
11
11
 
12
- defaults: &defaults
12
+ defaults:
13
13
  enable_platform: true
14
14
  enable_app_directory: true
15
15
  enable_embedded_applications: true
16
16
  enable_mobile_applications: true
17
- enable_developer_agreement: false
18
17
  enable_app_statistics: false
19
18
  enable_api_verification: false
20
19
  api_explorer_app_id: 1 # make sure to create an application for the test tool
21
20
 
21
+ #############################################################################
22
+ # You can enforce users to accept the developers agreement before they
23
+ # become developers. To do so, enable the line below and provide path
24
+ # to your dev agreement.
25
+ #############################################################################
26
+ enable_developer_agreement: true
27
+ developer_agreement_path: /developer_agreement.html
28
+
22
29
  #############################################################################
23
30
  # Platform best run with caching enabled
24
31
  # You can configure cache adapter and store parameters by providing the
@@ -52,7 +59,7 @@ defaults: &defaults
52
59
  # Site Integration Settings
53
60
  #############################################################################
54
61
  site_info:
55
- title: "Sample Application"
62
+ title: "Bookmarklet"
56
63
  logo_url: "/assets/platform/platform5.png"
57
64
  base_url: "localhost:3000"
58
65
  contact_email: feedback@oauthx.com
@@ -118,19 +125,13 @@ defaults: &defaults
118
125
  # You can overload any feature defined in the defaults for any environment
119
126
  #############################################################################
120
127
  development:
121
- <<: *defaults
122
128
 
123
129
  test:
124
- <<: *defaults
125
130
 
126
131
  qa:
127
- <<: *defaults
128
132
 
129
133
  stage:
130
- <<: *defaults
131
134
 
132
135
  production:
133
- <<: *defaults
134
136
 
135
137
  sandbox:
136
- <<: *defaults
@@ -1,39 +1,20 @@
1
- defaults: &defaults
2
- google:
3
- name: "Google"
4
- description: "Google Search Engine"
5
- url: "http://www.google.com"
6
- contact_email: "apps@railsplatform.org"
7
- category_keywords: ["all"]
8
- icon_path: "/public/platform/images/apps/app_icon.gif"
9
- logo_path: "/public/platform/images/apps/app_logo.gif"
10
-
11
- yahoo:
12
- name: "Yahoo"
13
- description: "Yahoo Search Engine"
14
- url: "http://www.yahoo.com"
15
- contact_email: "apps@railsplatform.org"
16
- category_keywords: ["all"]
17
- icon_path: "/public/platform/images/apps/app_icon.gif"
18
- logo_path: "/public/platform/images/apps/app_logo.gif"
1
+ defaults:
2
+ api_explorer:
3
+ name: "API Explorer"
4
+ description: "Allows developers to test API without having to create any applications"
19
5
 
20
6
  #############################################################################
21
7
  # Environment Settings
22
8
  # You can overload any feature defined in the defaults for any environment
23
9
  #############################################################################
24
10
  development:
25
- <<: *defaults
26
11
 
27
12
  test:
28
- <<: *defaults
29
13
 
30
14
  qa:
31
- <<: *defaults
32
15
 
33
16
  stage:
34
- <<: *defaults
35
17
 
36
18
  production:
37
- <<: *defaults
38
19
 
39
20
 
@@ -1,4 +1,4 @@
1
- defaults: &defaults
1
+ defaults:
2
2
  all:
3
3
  position: 1
4
4
  name: "All Apps"
@@ -39,18 +39,13 @@ defaults: &defaults
39
39
  # You can overload any feature defined in the defaults for any environment
40
40
  #############################################################################
41
41
  development:
42
- <<: *defaults
43
42
 
44
43
  test:
45
- <<: *defaults
46
44
 
47
45
  qa:
48
- <<: *defaults
49
46
 
50
47
  stage:
51
- <<: *defaults
52
48
 
53
49
  production:
54
- <<: *defaults
55
50
 
56
51