activate-admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.components +9 -0
  2. data/.gitignore +29 -0
  3. data/Gemfile +57 -0
  4. data/Gemfile.lock +184 -0
  5. data/Procfile +1 -0
  6. data/README.md +54 -0
  7. data/Rakefile +6 -0
  8. data/activate-admin.gemspec +19 -0
  9. data/admin/app.rb +160 -0
  10. data/admin/assets/fonts/FontAwesome.otf +0 -0
  11. data/admin/assets/fonts/fontawesome-webfont.eot +0 -0
  12. data/admin/assets/fonts/fontawesome-webfont.ttf +0 -0
  13. data/admin/assets/fonts/fontawesome-webfont.woff +0 -0
  14. data/admin/assets/javascripts/bootstrap-wysihtml5-0.0.2.js +321 -0
  15. data/admin/assets/javascripts/bootstrap.min.js +6 -0
  16. data/admin/assets/javascripts/jquery-1.9.1.min.js +5 -0
  17. data/admin/assets/javascripts/jquery-migrate-1.1.1.js +511 -0
  18. data/admin/assets/javascripts/jquery-ujs.js +95 -0
  19. data/admin/assets/javascripts/jquery.ba-bbq.min.js +18 -0
  20. data/admin/assets/javascripts/wysihtml5-0.3.0.js +9530 -0
  21. data/admin/assets/stylesheets/bootstrap-responsive.min.css +9 -0
  22. data/admin/assets/stylesheets/bootstrap-wysihtml5-0.0.2.css +44 -0
  23. data/admin/assets/stylesheets/bootstrap.min.css +9 -0
  24. data/admin/assets/stylesheets/font-awesome.min.css +34 -0
  25. data/admin/helpers/helpers.rb +19 -0
  26. data/admin/views/build.erb +111 -0
  27. data/admin/views/home.erb +24 -0
  28. data/admin/views/index.erb +108 -0
  29. data/admin/views/layouts/application.erb +75 -0
  30. data/admin/views/login_page.erb +31 -0
  31. data/config/apps.rb +5 -0
  32. data/config/boot.rb +26 -0
  33. data/config/mongoid.yml +14 -0
  34. data/config/navigation.rb +3 -0
  35. data/config.ru +9 -0
  36. data/lib/activate-admin/version.rb +3 -0
  37. data/lib/activate-admin.rb +6 -0
  38. data/lib/assetpack_patch.rb +18 -0
  39. data/lib/date_formats.rb +11 -0
  40. data/lib/datetime_helpers.rb +32 -0
  41. data/lib/dragonfly.rb +30 -0
  42. data/lib/kaminari/_first_page.html.erb +12 -0
  43. data/lib/kaminari/_gap.html.erb +8 -0
  44. data/lib/kaminari/_last_page.html.erb +13 -0
  45. data/lib/kaminari/_next_page.html.erb +13 -0
  46. data/lib/kaminari/_page.html.erb +12 -0
  47. data/lib/kaminari/_paginator.html.erb +25 -0
  48. data/lib/kaminari/_prev_page.html.erb +13 -0
  49. data/lib/kaminari.rb +51 -0
  50. data/lib/param_helpers.rb +41 -0
  51. metadata +113 -0
data/.components ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ :orm: mongoid
3
+ :test: none
4
+ :mock: none
5
+ :script: jquery
6
+ :renderer: erb
7
+ :stylesheet: none
8
+ :namespace: ActivateAdmin
9
+ :migration_format: number
data/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ bin/*
5
+ vendor/gems/*
6
+ !vendor/gems/cache/
7
+ .sass-cache/*
8
+ nbproject
9
+ .env
10
+ models/*
11
+
12
+ *.gem
13
+ *.rbc
14
+ .bundle
15
+ .config
16
+ coverage
17
+ InstalledFiles
18
+ lib/bundler/man
19
+ pkg
20
+ rdoc
21
+ spec/reports
22
+ test/tmp
23
+ test/version_tmp
24
+ tmp
25
+
26
+ # YARD artifacts
27
+ .yardoc
28
+ _yardoc
29
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,57 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '1.9.3'
4
+ gem 'puma'
5
+ gem 'padrino', '0.11.1'
6
+ gem 'rake'
7
+
8
+ # Asset pipeline
9
+ gem 'sinatra-assetpack', :require => 'sinatra/assetpack'
10
+
11
+ # Data storage
12
+ gem 'mongoid', github: 'mongoid/mongoid'
13
+ gem 'dragonfly'
14
+ gem 'mongo' # MongoDataStore
15
+ gem 'bson_ext' # MongoDataStore
16
+ # gem 'fog' # S3DataStore
17
+
18
+ # Authentication
19
+ gem 'bcrypt-ruby', require: 'bcrypt'
20
+ gem 'omniauth'
21
+ gem 'omniauth-twitter'
22
+ gem 'omniauth-facebook'
23
+ gem 'omniauth-google-oauth2'
24
+ gem 'omniauth-linkedin'
25
+
26
+ # Timezones
27
+ gem 'tzinfo'
28
+
29
+ # Navigation
30
+ gem 'sinatra-simple-navigation', require: 'sinatra/simple-navigation'
31
+
32
+ # Pagination
33
+ gem 'kaminari', require: 'kaminari/sinatra'
34
+ gem 'actionpack', '4.0.0.beta1'
35
+
36
+ # Autolinking
37
+ # gem 'rinku'
38
+
39
+ # Asynchronous tasks
40
+ # gem 'delayed_job_mongoid'
41
+
42
+ # Error reporting
43
+ # gem 'airbrake'
44
+ gem 'backtrace_shortener'
45
+
46
+ # Interacting with other websites
47
+ # gem 'mechanize'
48
+ # gem 'pismo'
49
+ # gem 'oauth'
50
+ # gem 'twitter'
51
+ # gem 'koala'
52
+ # gem 'hominid'
53
+
54
+ # Caching
55
+ # gem 'rack-cache'
56
+ # gem 'memcachier'
57
+ # gem 'dalli'
data/Gemfile.lock ADDED
@@ -0,0 +1,184 @@
1
+ GIT
2
+ remote: git://github.com/mongoid/mongoid.git
3
+ revision: 4a931ca105fddf59cc2f8619e973233376cf4b67
4
+ specs:
5
+ mongoid (4.0.0)
6
+ activemodel (~> 4.0.0.beta)
7
+ moped (~> 1.4.2)
8
+ origin (~> 1.0)
9
+ tzinfo (~> 0.3.22)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionpack (4.0.0.beta1)
15
+ activesupport (= 4.0.0.beta1)
16
+ builder (~> 3.1.0)
17
+ erubis (~> 2.7.0)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ activemodel (4.0.0.beta1)
21
+ activesupport (= 4.0.0.beta1)
22
+ builder (~> 3.1.0)
23
+ activesupport (4.0.0.beta1)
24
+ i18n (~> 0.6.2)
25
+ minitest (~> 4.2)
26
+ multi_json (~> 1.3)
27
+ thread_safe (~> 0.1)
28
+ tzinfo (~> 0.3.33)
29
+ atomic (1.1.7)
30
+ atomic (1.1.7-java)
31
+ backports (3.3.0)
32
+ backtrace_shortener (0.1.0)
33
+ bcrypt-ruby (3.0.1)
34
+ bcrypt-ruby (3.0.1-java)
35
+ bson (1.8.5)
36
+ bson (1.8.5-java)
37
+ bson_ext (1.8.4)
38
+ bson (~> 1.8.4)
39
+ builder (3.1.4)
40
+ dragonfly (0.9.14)
41
+ multi_json (~> 1.0)
42
+ rack
43
+ erubis (2.7.0)
44
+ faraday (0.8.7)
45
+ multipart-post (~> 1.1)
46
+ hashie (2.0.3)
47
+ http_router (0.11.0)
48
+ rack (>= 1.0.0)
49
+ url_mount (~> 0.2.1)
50
+ httpauth (0.2.0)
51
+ i18n (0.6.4)
52
+ jsmin (1.0.1)
53
+ jwt (0.1.8)
54
+ multi_json (>= 1.5)
55
+ kaminari (0.14.1)
56
+ actionpack (>= 3.0.0)
57
+ activesupport (>= 3.0.0)
58
+ mail (2.5.3)
59
+ i18n (>= 0.4.0)
60
+ mime-types (~> 1.16)
61
+ treetop (~> 1.4.8)
62
+ mime-types (1.22)
63
+ minitest (4.7.1)
64
+ mongo (1.8.5)
65
+ bson (~> 1.8.5)
66
+ moped (1.4.5)
67
+ multi_json (1.7.2)
68
+ multipart-post (1.2.0)
69
+ oauth (0.4.7)
70
+ oauth2 (0.8.1)
71
+ faraday (~> 0.8)
72
+ httpauth (~> 0.1)
73
+ jwt (~> 0.1.4)
74
+ multi_json (~> 1.0)
75
+ rack (~> 1.2)
76
+ omniauth (1.1.4)
77
+ hashie (>= 1.2, < 3)
78
+ rack
79
+ omniauth-facebook (1.4.1)
80
+ omniauth-oauth2 (~> 1.1.0)
81
+ omniauth-google-oauth2 (0.1.13)
82
+ omniauth (~> 1.0)
83
+ omniauth-oauth2
84
+ omniauth-linkedin (0.1.0)
85
+ omniauth-oauth (~> 1.0)
86
+ omniauth-oauth (1.0.1)
87
+ oauth
88
+ omniauth (~> 1.0)
89
+ omniauth-oauth2 (1.1.1)
90
+ oauth2 (~> 0.8.0)
91
+ omniauth (~> 1.0)
92
+ omniauth-twitter (0.0.16)
93
+ multi_json (~> 1.3)
94
+ omniauth-oauth (~> 1.0)
95
+ origin (1.0.11)
96
+ padrino (0.11.1)
97
+ padrino-admin (= 0.11.1)
98
+ padrino-cache (= 0.11.1)
99
+ padrino-core (= 0.11.1)
100
+ padrino-gen (= 0.11.1)
101
+ padrino-helpers (= 0.11.1)
102
+ padrino-mailer (= 0.11.1)
103
+ padrino-admin (0.11.1)
104
+ padrino-core (= 0.11.1)
105
+ padrino-helpers (= 0.11.1)
106
+ padrino-cache (0.11.1)
107
+ padrino-core (= 0.11.1)
108
+ padrino-helpers (= 0.11.1)
109
+ padrino-core (0.11.1)
110
+ activesupport (>= 3.1.0)
111
+ http_router (~> 0.11.0)
112
+ rack-protection (>= 1.5.0)
113
+ sinatra (~> 1.4.2)
114
+ thor (~> 0.17.0)
115
+ tilt (~> 1.3.0)
116
+ padrino-gen (0.11.1)
117
+ bundler (~> 1.0)
118
+ padrino-core (= 0.11.1)
119
+ padrino-helpers (0.11.1)
120
+ i18n (~> 0.6)
121
+ padrino-core (= 0.11.1)
122
+ padrino-mailer (0.11.1)
123
+ mail (~> 2.5.3)
124
+ padrino-core (= 0.11.1)
125
+ polyglot (0.3.3)
126
+ puma (1.6.3)
127
+ rack (~> 1.2)
128
+ puma (1.6.3-java)
129
+ rack (~> 1.2)
130
+ rack (1.5.2)
131
+ rack-protection (1.5.0)
132
+ rack
133
+ rack-test (0.6.2)
134
+ rack (>= 1.0)
135
+ rake (10.0.4)
136
+ simple-navigation (3.10.1)
137
+ activesupport (>= 2.3.2)
138
+ sinatra (1.4.2)
139
+ rack (~> 1.5, >= 1.5.2)
140
+ rack-protection (~> 1.4)
141
+ tilt (~> 1.3, >= 1.3.4)
142
+ sinatra-assetpack (0.2.1)
143
+ backports
144
+ jsmin
145
+ rack-test
146
+ sinatra
147
+ tilt (>= 1.3.0)
148
+ sinatra-simple-navigation (3.6.0)
149
+ simple-navigation (>= 3.10.1)
150
+ thor (0.17.0)
151
+ thread_safe (0.1.0)
152
+ atomic
153
+ tilt (1.3.7)
154
+ treetop (1.4.12)
155
+ polyglot
156
+ polyglot (>= 0.3.1)
157
+ tzinfo (0.3.37)
158
+ url_mount (0.2.1)
159
+ rack
160
+
161
+ PLATFORMS
162
+ java
163
+ ruby
164
+
165
+ DEPENDENCIES
166
+ actionpack (= 4.0.0.beta1)
167
+ backtrace_shortener
168
+ bcrypt-ruby
169
+ bson_ext
170
+ dragonfly
171
+ kaminari
172
+ mongo
173
+ mongoid!
174
+ omniauth
175
+ omniauth-facebook
176
+ omniauth-google-oauth2
177
+ omniauth-linkedin
178
+ omniauth-twitter
179
+ padrino (= 0.11.1)
180
+ puma
181
+ rake
182
+ sinatra-assetpack
183
+ sinatra-simple-navigation
184
+ tzinfo
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec puma -t 1:4 -e $RACK_ENV -p $PORT
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ activate-admin
2
+ =================
3
+
4
+ ``` ruby
5
+ :datetime
6
+ :check_box
7
+ :file
8
+ :slug
9
+ :image # define self#rotate_fieldname_by for rotation
10
+ :text_area
11
+ :password
12
+ :select # define self.options
13
+ :lookup # define OtherModel#lookup
14
+ :collection # define OtherModel#lookup
15
+ :text # default
16
+
17
+ def self.fields_for_index
18
+ [:name, :email, :role, :time_zone]
19
+ end
20
+
21
+ def self.fields_for_form
22
+ {
23
+ :name => :text,
24
+ :email => :text,
25
+ :picture => :image,
26
+ :role => :select,
27
+ :time_zone => :select,
28
+ :password => :password,
29
+ :password_confirmation => :password,
30
+ :connections => :collection
31
+ }
32
+ end
33
+
34
+ def self.new_hints
35
+ {
36
+ :password => 'Leave blank to keep existing password'
37
+ }
38
+ end
39
+
40
+ def self.edit_hints
41
+ {
42
+ :password => 'Leave blank to keep existing password'
43
+ }
44
+ end
45
+
46
+ def filter_options
47
+ {
48
+ :q => 'query',
49
+ :f => [:field1 => 'query1', :field2 => 'query2'],
50
+ :o => 'order',
51
+ :d => 'desc'
52
+ }
53
+ end
54
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'padrino-core/cli/rake'
3
+
4
+ PadrinoTasks.use(:database)
5
+ PadrinoTasks.use(:mongoid)
6
+ PadrinoTasks.init
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/activate-admin/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Stephen Reid"]
6
+ gem.email = ["postscript07@gmail.com"]
7
+ gem.description = %q{An admin gem for Padrino/mongoid}
8
+ gem.summary = %q{A powerful, lightweight admin gem for Padrino/mongoid with support for a variety of different field types}
9
+ gem.homepage = "https://github.com/postscript07/activate-admin"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "activate-admin"
15
+ gem.require_paths = ["lib", "app"]
16
+ gem.version = ActivateAdmin::VERSION
17
+
18
+ gem.add_dependency "padrino-core"
19
+ end
data/admin/app.rb ADDED
@@ -0,0 +1,160 @@
1
+ module ActivateAdmin
2
+ class App < Padrino::Application
3
+ register Padrino::Rendering
4
+ register Padrino::Helpers
5
+ register Sinatra::SimpleNavigation
6
+ helpers Kaminari::Helpers::SinatraHelpers
7
+ helpers DatetimeHelpers
8
+ helpers ParamHelpers
9
+ use Dragonfly::Middleware, :dragonfly
10
+
11
+ enable :sessions
12
+ set :show_exceptions, true
13
+
14
+ register Sinatra::AssetPack
15
+ assets {
16
+ serve '/css', from: '/assets/stylesheets'
17
+ serve '/fonts', from: '/assets/fonts'
18
+ serve '/js', from: '/assets/javascripts'
19
+ css :app, [
20
+ '/css/bootstrap.min.css',
21
+ '/css/bootstrap-responsive.min.css',
22
+ '/css/font-awesome.min.css',
23
+ '/css/bootstrap-wysihtml5-0.0.2.css'
24
+
25
+ ]
26
+ js :app, [
27
+ '/js/jquery-1.9.1.min.js',
28
+ '/js/jquery-migrate-1.1.1.js',
29
+ '/js/jquery-ujs.js',
30
+ '/js/bootstrap.min.js',
31
+ '/js/wysihtml5-0.3.0.js',
32
+ '/js/bootstrap-wysihtml5-0.0.2.js',
33
+ '/js/jquery.ba-bbq.min.js'
34
+ ]
35
+ prebuild true
36
+ }
37
+
38
+ before do
39
+ redirect url_for(:login) unless [url_for(:login), url_for(:logout)].include?(request.path) or (current_account and current_account.role == 'admin')
40
+ fix_params!
41
+ Time.zone = current_account.time_zone if current_account and current_account.time_zone
42
+ end
43
+
44
+ get :home, :map => '/' do
45
+ erb :home
46
+ end
47
+
48
+ get :index, :map => '/index/:model', :provides => [:html, :csv] do
49
+ if model.respond_to?(:filter_options)
50
+ @q, @f, @o, @d, = model.filter_options[:q], model.filter_options[:f], model.filter_options[:o], model.filter_options[:d]
51
+ end
52
+ @q = params[:q] if params[:q]
53
+ @qf = params[:qf] if params[:qf]
54
+ @f = params[:f] if params[:f]
55
+ @o = params[:o].to_sym if params[:o]
56
+ @d = params[:d].to_sym if params[:d]
57
+ @resources = model.all
58
+ if @qf == 'search'
59
+ @resources = @resources.or(model.fields.map { |field| {field[0] => /#{@q}/i } if field[1].type == String and !field[0].starts_with?('_') }.compact)
60
+ elsif @qf == 'eval'
61
+ @resources = eval("@resources.#{@q}")
62
+ end
63
+ @f.each { |k,v|
64
+ if model.fields[k] and v
65
+ if model.fields[k].type == Boolean
66
+ @resources = (v == 'true' ? @resources.where(k.to_sym => true) : @resources.where(k.to_sym.ne => true))
67
+ else
68
+ @resources = @resources.where(k.to_sym => /#{v}/i)
69
+ end
70
+ end
71
+ } if @f
72
+ @resources = @resources.order_by(@o.to_sym.send(@d)) if @o and @d
73
+ case content_type
74
+ when :html
75
+ @resources = @resources.page(params[:page]).per(10)
76
+ instance_variable_set("@#{model.to_s.underscore.pluralize}", @resources)
77
+ erb :index
78
+ when :csv
79
+ CSV.generate do |csv|
80
+ csv << model.fields_for_index
81
+ @resources.each do |resource|
82
+ csv << model.fields_for_index.map { |fieldname| resource.send(fieldname) }
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ get :new, :map => '/new/:model' do
89
+ @resource = model.new
90
+ instance_variable_set("@#{model.to_s.underscore}", @resource)
91
+ erb :build
92
+ end
93
+
94
+ post :new, :map => '/new/:model' do
95
+ @resource = model.new(params[model.to_s.underscore])
96
+ instance_variable_set("@#{model.to_s.underscore}", @resource)
97
+ if @resource.save
98
+ flash[:notice] = "<strong>Awesome!</strong> The #{human_model_name(model).downcase} was created successfully."
99
+ redirect url_for(:index, :model => model.to_s)
100
+ else
101
+ flash.now[:error] = "<strong>Oops.</strong> Some errors prevented the #{human_model_name(model).downcase} from being saved."
102
+ erb :build
103
+ end
104
+ end
105
+
106
+ get :edit, :map => '/edit/:model/:id' do
107
+ @resource = model.find(params[:id])
108
+ instance_variable_set("@#{model.to_s.underscore}", @resource)
109
+ erb :build
110
+ end
111
+
112
+ post :edit, :map => '/edit/:model/:id' do
113
+ @resource = model.find(params[:id])
114
+ instance_variable_set("@#{model.to_s.underscore}", @resource)
115
+ if @resource.update_attributes(params[model.to_s.underscore])
116
+ flash[:notice] = "<strong>Sweet!</strong> The #{human_model_name(model).downcase} was updated successfully."
117
+ redirect url_for(:edit, :model => model.to_s, :id => @resource.id)
118
+ else
119
+ flash.now[:error] = "<strong>Oops.</strong> Some errors prevented the #{human_model_name(model).downcase} from being saved."
120
+ erb :build
121
+ end
122
+ end
123
+
124
+ get :destroy, :map => '/destroy/:model/:id' do
125
+ resource = model.find(params[:id])
126
+ if resource.destroy
127
+ flash[:notice] = "<strong>Boom!</strong> The #{human_model_name(model).downcase} was deleted."
128
+ else
129
+ flash[:error] = "<strong>Darn!</strong> The #{human_model_name(model).downcase} couldn't be deleted."
130
+ end
131
+ redirect url_for(:index, :model => model.to_s)
132
+ end
133
+
134
+ get :login, :map => '/login' do
135
+ erb :login_page
136
+ end
137
+
138
+ post :login, :map => '/login' do
139
+ if account = Account.authenticate(params[:email], params[:password])
140
+ session[:account_id] = account.id
141
+ flash[:notice] = "Logged in successfully."
142
+ redirect url_for(:home)
143
+ elsif Padrino.env == :development && params[:bypass]
144
+ account = Account.first
145
+ session[:account_id] = account.id
146
+ flash[:notice] = "Logged in successfully."
147
+ redirect url_for(:home)
148
+ else
149
+ params[:email], params[:password] = h(params[:email]), h(params[:password])
150
+ flash[:warning] = "Login or password wrong."
151
+ redirect url_for(:login)
152
+ end
153
+ end
154
+
155
+ get :logout, :map => '/logout' do
156
+ session.clear
157
+ redirect url_for(:login)
158
+ end
159
+ end
160
+ end
Binary file