milia 1.2.1 → 1.3.1.beta1

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/confirmations_controller.rb +7 -7
  3. data/app/controllers/registrations_controller.rb +13 -19
  4. data/app/views/devise/registrations/new.html.haml +53 -0
  5. data/lib/generators/milia/install_generator.rb +44 -41
  6. data/lib/generators/milia/templates/devise_permitted_parameters.rb +18 -0
  7. data/lib/generators/milia/templates/initializer.rb +3 -9
  8. data/lib/milia.rb +3 -22
  9. data/lib/milia/base.rb +88 -109
  10. data/lib/milia/control.rb +25 -25
  11. data/lib/milia/invite_member.rb +6 -6
  12. data/lib/milia/version.rb +1 -1
  13. metadata +16 -184
  14. data/.document +0 -5
  15. data/.gitignore +0 -94
  16. data/.ruby-gemset +0 -1
  17. data/.ruby-version +0 -1
  18. data/.slugignore +0 -2
  19. data/.travis.yml +0 -4
  20. data/Gemfile +0 -4
  21. data/LICENSE.txt +0 -20
  22. data/README.md +0 -1207
  23. data/Rakefile +0 -1
  24. data/doc/gemfile_addition.txt +0 -28
  25. data/doc/manual_sample.sh +0 -816
  26. data/doc/ref_notes.txt +0 -155
  27. data/doc/sample.sh +0 -276
  28. data/markdown.rb +0 -38
  29. data/milia.gemspec +0 -29
  30. data/test/.ruby-gemset +0 -1
  31. data/test/.ruby-version +0 -1
  32. data/test/Gemfile +0 -81
  33. data/test/Gemfile.lock +0 -223
  34. data/test/README.md +0 -83
  35. data/test/Rakefile +0 -6
  36. data/test/app/assets/javascripts/application.js +0 -16
  37. data/test/app/assets/stylesheets/application.css +0 -13
  38. data/test/app/controllers/application_controller.rb +0 -13
  39. data/test/app/controllers/home_controller.rb +0 -10
  40. data/test/app/helpers/application_helper.rb +0 -2
  41. data/test/app/models/member.rb +0 -34
  42. data/test/app/models/post.rb +0 -14
  43. data/test/app/models/team.rb +0 -9
  44. data/test/app/models/team_asset.rb +0 -6
  45. data/test/app/models/tenant.rb +0 -54
  46. data/test/app/models/user.rb +0 -14
  47. data/test/app/models/zine.rb +0 -8
  48. data/test/app/views/home/index.html.erb +0 -2
  49. data/test/app/views/home/show.html.erb +0 -2
  50. data/test/app/views/layouts/application.html.erb +0 -14
  51. data/test/bin/bundle +0 -3
  52. data/test/bin/rails +0 -4
  53. data/test/bin/rake +0 -4
  54. data/test/config/application.rb +0 -36
  55. data/test/config/boot.rb +0 -4
  56. data/test/config/database.yml +0 -25
  57. data/test/config/environment.rb +0 -5
  58. data/test/config/environments/development.rb +0 -48
  59. data/test/config/environments/production.rb +0 -95
  60. data/test/config/environments/test.rb +0 -42
  61. data/test/config/initializers/backtrace_silencers.rb +0 -7
  62. data/test/config/initializers/devise.rb +0 -254
  63. data/test/config/initializers/filter_parameter_logging.rb +0 -4
  64. data/test/config/initializers/inflections.rb +0 -16
  65. data/test/config/initializers/milia.rb +0 -51
  66. data/test/config/initializers/mime_types.rb +0 -5
  67. data/test/config/initializers/secret_token.rb +0 -12
  68. data/test/config/initializers/session_store.rb +0 -3
  69. data/test/config/initializers/wrap_parameters.rb +0 -14
  70. data/test/config/locales/en.yml +0 -23
  71. data/test/config/routes.rb +0 -77
  72. data/test/db/migrate/20111012050200_add_sessions_table.rb +0 -12
  73. data/test/db/migrate/20111012050340_devise_create_users.rb +0 -48
  74. data/test/db/migrate/20111012050532_create_tenants.rb +0 -11
  75. data/test/db/migrate/20111012050600_create_tenants_users_join_table.rb +0 -8
  76. data/test/db/migrate/20111012050650_create_members.rb +0 -12
  77. data/test/db/migrate/20111012231923_create_posts.rb +0 -12
  78. data/test/db/migrate/20111013050657_create_zines.rb +0 -10
  79. data/test/db/migrate/20111013050753_create_teams.rb +0 -10
  80. data/test/db/migrate/20111013050837_create_team_assets.rb +0 -11
  81. data/test/db/schema.rb +0 -126
  82. data/test/db/seeds.rb +0 -7
  83. data/test/test/controllers/home_controller_test.rb +0 -132
  84. data/test/test/ctlr_test_helper.rb +0 -11
  85. data/test/test/fixtures/members.yml +0 -35
  86. data/test/test/fixtures/posts.yml +0 -96
  87. data/test/test/fixtures/team_assets.yml +0 -30
  88. data/test/test/fixtures/teams.yml +0 -17
  89. data/test/test/fixtures/tenants.yml +0 -12
  90. data/test/test/fixtures/tenants_users.yml +0 -15
  91. data/test/test/fixtures/users.yml +0 -33
  92. data/test/test/fixtures/zines.yml +0 -25
  93. data/test/test/models/member_test.rb +0 -75
  94. data/test/test/models/post_test.rb +0 -66
  95. data/test/test/models/team_test.rb +0 -49
  96. data/test/test/models/tenant_test.rb +0 -228
  97. data/test/test/models/user_test.rb +0 -182
  98. data/test/test/models/zine_test.rb +0 -40
  99. data/test/test/test_helper.rb +0 -31
@@ -1,155 +0,0 @@
1
- DEFAULT_SCOPE RAILS 3.1 (from https://gist.github.com/958338)
2
- ================================================================================
3
- default_scope can take a block, lambda, or any other object which responds
4
- to call for lazy evaluation:
5
-
6
- default_scope { ... }
7
- default_scope lambda { ... }
8
- default_scope method(:foo)
9
-
10
- This feature was originally implemented by Tim Morgan, but was then removed in
11
- favour of defining a default_scope class method,
12
- but has now been added back in by Jon Leighton.
13
- The relevant lighthouse ticket is #1812.
14
-
15
- Default scopes are now evaluated at the latest possible moment,
16
- to avoid problems where scopes would be created which would implicitly contain
17
- the default scope, which would then be impossible to get rid of via
18
- Model.unscoped.
19
- No
20
- te that this means that if you are inspecting the internal structure of an
21
- ActiveRecord::Relation, it will not contain the default scope, though the
22
- resulting query will do. You can get a relation containing the default scope by
23
- calling ActiveRecord#with_default_scope, though this is not part of the public API.
24
-
25
- Calling default_scope multiple times in a class
26
- (including when a superclass calls default_scope) is deprecated.
27
- The current behavior is that this will merge the default scopes together:
28
-
29
- class Post < ActiveRecord::Base # Rails 3.1
30
- default_scope where(:published => true)
31
- default_scope where(:hidden => false)
32
- # The default scope is now: where(:published => true, :hidden => false)
33
- end
34
-
35
- In Rails 3.2, the behavior will be changed to overwrite previous scopes:
36
-
37
- class Post < ActiveRecord::Base # Rails 3.2
38
- default_scope where(:published => true)
39
- default_scope where(:hidden => false)
40
- # The default scope is now: where(:hidden => false)
41
- end
42
- If you wish to merge default scopes in special ways, it is recommended to define
43
- your default scope as a class method and use the standard techniques for
44
- sharing code (inheritance, mixins, etc.):
45
-
46
- class Post < ActiveRecord::Base
47
- def self.default_scope
48
- where(:published => true).where(:hidden => false)
49
- end
50
- end
51
-
52
- http://samuel.kadolph.com/2010/12/simple-rails-multi-tenancy/
53
- ===================================================================
54
- class Tenant < ActiveRecord::Base
55
- class << self
56
- def current
57
- Thread.current[:current_tenant]
58
- end
59
-
60
- def current=(tenant)
61
- Thread.current[:current_tenant] = tenant
62
- end
63
- end
64
- end
65
-
66
- app/models/tenant_scoped_model.rb
67
- class TenantScopedModel < ActiveRecord::Base
68
- self.abstract_class = true
69
-
70
- class << self
71
- protected
72
- def current_scoped_methods
73
- last = scoped_methods.last
74
- last.respond_to?(:call) ? relation.scoping { last.call } : last
75
- end
76
- end
77
-
78
- belongs_to :tenant
79
-
80
- default_scope lambda { where('tenant_id = ?', Tenant.current) }
81
-
82
- before_save { self.tenant = Tenant.current }
83
- end
84
-
85
- class ApplicationController < ActionController::Base
86
- before_filter do
87
- @tenant = Tenant.current = Tenant.find_by_host!(request.host)
88
- end
89
- end
90
-
91
- Caveats
92
-
93
- Calling unscoped bypasses the default_scope; this is both good and bad because you can get all partitioned data from a model regardless of the current tenant.
94
- You will get errors in the console when working with a scoped model unless you set Tenant.current.
95
- before_save { self.tenant = Tenant.current } is necessary because rails does not automatically set the attributes from our default_scope because it is a lambda.
96
-
97
-
98
- http://www.justinball.com/2011/09/27/customizing-views-for-a-multi-tenant-application-using-ruby-on-rails-custom-resolvers/
99
- ===============================================================================
100
- but setting a global on the current thread felt like a big hack. (Here's a good article on Thread.current ) Lucky for me Jose was willing to spend a little time working with me and the resulting code works without globals. Instead of passing a global around we removed the Singleton code from the resolver and create an instance of the resolver per each account:
101
-
102
-
103
- class ApplicationController < ActionController::Base
104
- before_filter :set_resolver
105
-
106
- def current_account
107
- @current_account ||= Account.find_by_domain(request.host) || Account.find_by_code(request.subdomains.first) || Account.first
108
- end
109
-
110
- @@account_resolver = {}
111
-
112
- def account_resolver_for(account)
113
- @@account_resolver[account.id] ||= CustomView::Resolver.new(account)
114
- end
115
-
116
- def set_resolver
117
- return unless current_account
118
- resolver = account_resolver_for(current_account)
119
- resolver.update_account(current_account)
120
- prepend_view_path resolver
121
- end
122
-
123
- end
124
- class Resolver < ActionView::Resolver
125
-
126
- def initialize(account)
127
- @account = account
128
- end
129
-
130
- # Check if the custom_view_cache_count is still the same, if not clear the cache
131
- def update_account(updated_account)
132
- self.clear_cache unless @account.custom_view_cache_count == updated_account.custom_view_cache_count
133
- @account = updated_account
134
- end
135
- end
136
-
137
- POSTGRES RULES
138
- ===============================================================================
139
- 36.2. Views and the Rule System
140
- Views in PostgreSQL are implemented using the rule system.
141
- In fact, there is essentially no difference between:
142
-
143
- CREATE VIEW myview AS SELECT * FROM mytab;
144
-
145
- compared against the two commands:
146
-
147
- CREATE TABLE myview (same column list as mytab);
148
- CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
149
- SELECT * FROM mytab;
150
-
151
- because this is exactly what the CREATE VIEW command does internally.
152
- This has some side effects. One of them is that the information about a view
153
- in the PostgreSQL system catalogs is exactly the same as it is for a table.
154
- So for the parser, there is absolutely no difference between a table and a view.
155
- They are the same thing: relations.
@@ -1,276 +0,0 @@
1
- # *********************************************************************
2
- # HOW TO SET IT UP -- sample-milia-app
3
- # *********************************************************************
4
- # This is how to get a working app using rails/milia/devise
5
- # together with a simple but attractive web-app-theme.
6
- # I have added generators which automate all of the steps listed in
7
- # manual_sample.sh (if you want to see the details).
8
- # It is based on my dev environment which is Ubuntu 13.10 on a PC. YMMV.
9
- #
10
- # The "app" itself is merely a simple barebones structure to display
11
- # an index page, require sign-in to do anything else, has a sign-up
12
- # page for starting a new organization (ie tenant), a way to send
13
- # invitations to other members, and a single tenanted model to prove
14
- # that tenanting is working.
15
- #
16
- # you can see an exact copy of the sample on github:
17
- # https://github.com/dsaronin/sample-milia-app
18
- #
19
- # *********************************************************************
20
- # RESOURCES
21
- # *********************************************************************
22
- # doc/sample.sh -- this document will ALWAYS be the most recent
23
- # (for example in the edge branch: "newdev")
24
- # doc/manual_sample.sh -- step-by-step instructions WITHOUT the generators.
25
- #
26
- # github.com/milia/wiki/sample-milia-app-tutorial
27
- # this should be the same as the sample.sh doc for the current
28
- # stable release (or last beta version); but markdown formatted
29
- # https://github.com/dsaronin/milia/wiki/sample-milia-app-tutorial
30
- # milia README:
31
- # this will be the knowledgable programmer's digest of the essentials
32
- # and thus it won't cover some of the intricacies of actually
33
- # implementing milia: either the tutorial or sample.sh will do that
34
- #
35
- # *********************************************************************
36
- # FEEDBACK
37
- # *********************************************************************
38
- # If you run into difficulties while following the steps here,
39
- # please be sure to reference the LINE NUMBER of the point at which
40
- # had a problem, as well as any output from that step.
41
- # BUT (caveat)
42
- # if you've gone commando and been making changes & enhancements OR
43
- # have been trying to roll out a full app, you're more or less on your
44
- # own. I strongly recommend experimenting with milia first in this
45
- # simple format, get it working, then ADD in increasing layers of
46
- # complexity and difficulty. Trying to make too many changes at once
47
- # is a recipe for difficulty in troubleshooting.
48
- # *********************************************************************
49
- # NOTES
50
- # *********************************************************************
51
- # Although this file has a ".sh" extension, it isn't fully executable
52
- # as a shell script. There are just too many things you'll have to
53
- # to do to help things along.
54
- # 1. follow everything exactly in the order given
55
- # 2. there's non-milia related stuff if you'll be using heroku to host
56
- # treat this as optional, if you'd like. but at least I know it
57
- # works as a completed app.
58
- # *********************************************************************
59
-
60
- # *********************************************************************
61
- # STEP 0 - PREREQUISITES & EXPECTED BACKGROUND PREPARATION
62
- # *********************************************************************
63
-
64
- # This background is what I've done on my Ubuntu dev workstation
65
- # so if you want to follow exactly, you'll need a similar setup.
66
- # None of this is required for milia, only to bring up this
67
- # sample-milia-app.
68
-
69
- # make sure you have your ssh keys gen'd
70
- $ ssh-keygen
71
-
72
- # make sure you have some basic packages on your system
73
- $ sudo apt-get install curl git vim vim-gnome
74
-
75
- # make sure you've set up a github account, and git globals
76
-
77
- # Install RVM on your system; see rvm.io for more information
78
- $ \curl -L https://get.rvm.io | bash -s stable
79
- # do any adjustments to your .bashrc, etc files as needed
80
-
81
- # make sure to install ruby 2.1.3
82
- $ rvm install 2.1.3
83
-
84
- # I have all my projects in a directory called "projectspace'
85
- $ mkdir projectspace
86
- $ rvm gemset create projectspace
87
- $ echo "projectspace" > projectspace/.ruby-gemset
88
- $ echo "2.1.3" > projectspace/.ruby-version
89
- $ cd projectspace
90
-
91
- # install rails (latest version)
92
- $ gem install rails
93
-
94
- # OPTIONAL -- get ready for heroku
95
- # set up a heroku account at: heroku.com
96
- # install heroku toolbelt: heroku, foreman
97
- $ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
98
- $ heroku login
99
-
100
- # set environment variable for later Procfile and later recaptcha
101
- # I put them in .bashrc
102
- export PORT=3000
103
- export RACK_ENV=development
104
- export SMTP_ENTRY=<my smtp password>
105
- # OPTIONAL: recaptcha keys
106
- export RECAPTCHA_PUBLIC_KEY=6LeYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKpT
107
- export RECAPTCHA_PRIVATE_KEY=6LeBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBgQBv
108
-
109
-
110
- # *********************************************************************
111
- # STEP 1 - CREATION OF SKELETON APP & REPOSITORY
112
- # *********************************************************************
113
-
114
- # GITHUB: create a new repository <your-new-app> for <git-user> (you)
115
- # anywhere below where you see "sample-milia-app", change it to <your-new-app>
116
-
117
- $ cd projectspace # if not there already
118
-
119
- $ rails new sample-milia-app --skip-bundle
120
- $ echo "sample-milia-app" > sample-milia-app/.ruby-gemset
121
- $ echo "2.1.3" > sample-milia-app/.ruby-version
122
- $ echo "web: bundle exec thin start -R config.ru -p $PORT -e $RACK_ENV" > sample-milia-app/Procfile
123
- $ rvm gemset create sample-milia-app
124
- $ cd sample-milia-app
125
-
126
- # change .gitignore to match your development environment
127
- # I just copy my standard .gitignore from another project
128
- # but you can copy mine from sample-milia-app on github.
129
- $ cp ../<an existing project>/.gitignore .
130
-
131
- $ git init
132
- $ git add --all .
133
- $ git commit -am 'initial commit'
134
- $ git remote add origin git@github.com:<git-user>/sample-milia-app.git
135
- $ git push -u origin master
136
-
137
- # *********************************************************************
138
- # STEP 2 - SET UP GEMFILE, BUNDLE INSTALL GEMS
139
- # *********************************************************************
140
-
141
- # EDIT Gemfile >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
142
- $ vim Gemfile
143
-
144
- # First, comment OUT the turbolinks gem
145
- # gem 'turbolinks'
146
-
147
- # then, enable rubyracer in Gemfile by de-commenting
148
- gem 'therubyracer', platforms: :ruby
149
-
150
- # finally, ADD the following lines to Gemfile >>>>>>>>>>>>>>>>>>>>>>
151
-
152
- ruby "2.1.3" # heroku likes this at the head, as line 2
153
-
154
- # =========================================================
155
- # sample-milia-app specific stuff
156
- # =========================================================
157
- # Bundle the extra gems:
158
- gem 'haml-rails'
159
- gem 'html2haml', :git => 'git://github.com/haml/html2haml.git' # "2.0.0.beta.2",
160
-
161
- # stuff that heroku likes to have
162
- gem 'thin'
163
- gem "SystemTimer", :require => "system_timer", :platforms => :ruby_18
164
- gem "rack-timeout"
165
- gem 'rails_12factor'
166
-
167
- # airbrake is optional and configured by config.use_airbrake in milia initializer
168
- # default is false; if you change it to true, uncomment out the line below
169
- # gem 'airbrake' # uncomment this if you will use airbrake for exception notifications
170
-
171
- gem 'web-app-theme', :git => 'git://github.com/dsaronin/web-app-theme.git'
172
- gem 'devise', '~>3.2'
173
- gem 'milia', :git => 'git://github.com/dsaronin/milia.git', :branch => 'v1.0.0-beta-7'
174
-
175
- #<<<< ADD <<<<<<<<<<<<<<<<<
176
- #<<<< EDIT <<<<<<<<<<<<<<<<<
177
-
178
- # EDIT: app/assets/javascripts/application.js >>>>>>>>>>>>>>>>>>>>>>>>
179
- # comment out turbolinks in your Javascript manifest file
180
- # we won't need turbolinks for this simple sample.
181
- // require turbolinks
182
- #<<<< EDIT <<<<<<<<<<<<<<<<<
183
-
184
- # BUNDLE install all the gems
185
- $ bundle install
186
-
187
-
188
- # *********************************************************************
189
- # STEP 3 - INSTALL milia (and automatically, devise), and app framework
190
- # *********************************************************************
191
- $ rails g milia:install --org_email='<your smtp email for dev work>'
192
- $ rails g web_app_theme:milia
193
-
194
- # to be able to receive the confirmation & activation emails,
195
- # you will need to complete entering in your email and smtp
196
- # information in the following places:
197
- # config/environments/development.rb
198
- # config/environments/production.rb
199
-
200
- # create the database
201
- $ rake db:create
202
- $ rake db:migrate
203
-
204
- # test by starting server:
205
- $ foreman start
206
-
207
- # *********************************************************************
208
- # STEP 4 - TEST SIGN UP, ACTIVATION, SIGN IN, SIGN OUT
209
- # *********************************************************************
210
- # CHECK-OUT: at your browser:
211
- http://localhost:3000/
212
-
213
- # sign up as a new user,
214
- # the log file will show that an email was sent
215
- # together with the activation code & URL
216
- # and if your email/password are correct, an email should have been sent as well!
217
- # copy & paste this address as-is into the browser address area & go to it to activate
218
- # it will take you to a sign in screen; sign in
219
- # REFRESH index page (to refresh the logout validity token)
220
- # sign out
221
- # sign in again as the user
222
- # you will have to first sign-up, confirm, then you can invite_member
223
- # sign-out, confirm new member, etc
224
-
225
- # stop/restart foreman
226
- # ^c stops foreman; foreman start restarts it; F5 refreshes the browser page
227
- #
228
- # *********************************************************************
229
- # STEP 5 - DEPLOYING SAMPLE-MILIA-APP TO HEROKU
230
- # *********************************************************************
231
-
232
- # Make sure that you've installed the heroku toolbelt, as shown in STEP 0.
233
- # Make sure that you've setup git repository for you app, as shown in STEP 1.
234
- # Open a terminal window and make sure you've cd to your project within the projectspace.
235
- # Make sure that you've setup your heroku credentials on your machine using
236
- $ heroku login
237
-
238
- # Create your project (we'll call it "sample-milia" in the examples here).
239
- $ heroku create sample-milia
240
-
241
- # Now setup the various add-ons we'll need:
242
- $ heroku addons:add sendgrid
243
-
244
- # Now setup any needed configurations variables
245
- $ heroku config:add BUNDLE_WITHOUT="development:test:linux:mac"
246
- $ heroku config:add RECAPTCHA_PUBLIC_KEY='<your public key>'
247
- $ heroku config:add RECAPTCHA_PRIVATE_KEY='<your private key>'
248
-
249
- # edit config/initializers/secret_token.rb
250
- # duplicate the secret_key_base line and rename it to secret_token
251
-
252
- # edit config/environments/production.rb line 4
253
- # put in the correct path for the hostname, and remove the https protocol if not needed
254
-
255
- # edit Gemfile and replace the sqlite3 line with the following:
256
- # Use sqlite3 as the dev/test database for Active Record
257
- gem 'sqlite3', :group => [:development, :test]
258
-
259
- # Use pg as the production database for heroku
260
- gem 'pg', :group => :production
261
-
262
- # then run bundle install, and commit to the repository
263
- $ bundle install
264
- $ git commit -am 'ready for heroku deploy'; git push origin master
265
-
266
- # now deploy to heroku
267
- $ git push heroku master
268
-
269
- # now migrate the database
270
- $ heroku run rake db:migrate
271
- $ heroku restart
272
-
273
- # go to browser and put in the correct address for your app on heroku:
274
-
275
- http://sample-milia.herokuapp.com
276
-
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'redcarpet'
5
-
6
- class ShowMd
7
-
8
- TEMPFILE = "/tmp/markdown.html"
9
-
10
- def initialize( file )
11
- @body = IO.read( file )
12
- end
13
-
14
- def markdown
15
- options = [ :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
16
-
17
- File.open( TEMPFILE, "w" ) do |file|
18
- file.write( RedcarpetCompat.new( @body, *options).to_html )
19
- end # do file
20
- end
21
-
22
- def show
23
- system("chromium-browser #{TEMPFILE} &")
24
- end
25
-
26
-
27
- end # class
28
-
29
- md = ShowMd.new( ARGV[0] )
30
- md.markdown
31
- md.show
32
-
33
- # puts RedcarpetCompat.new(ARGF.read,
34
- # :fenced_code,
35
- # :hard_wrap,
36
- # :filter_html,
37
- # :smart).to_html
38
-