phoenixbricks 3.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.txt +674 -0
  5. data/README.md +85 -0
  6. data/bin/rbricks +5 -0
  7. data/lib/railsbricks.rb +115 -0
  8. data/lib/railsbricks/app_generator.rb +352 -0
  9. data/lib/railsbricks/assets/config/admin_post_routes.rbr +3 -0
  10. data/lib/railsbricks/assets/config/application.yml +9 -0
  11. data/lib/railsbricks/assets/config/contact_routes.rbr +2 -0
  12. data/lib/railsbricks/assets/config/initializers/devise_email/devise.rb +267 -0
  13. data/lib/railsbricks/assets/config/initializers/devise_username/devise.rb +267 -0
  14. data/lib/railsbricks/assets/config/post_routes.rbr +2 -0
  15. data/lib/railsbricks/assets/config/routes.rb +15 -0
  16. data/lib/railsbricks/assets/config/unicorn.rb +22 -0
  17. data/lib/railsbricks/assets/controllers/admin/base_controller.rb +10 -0
  18. data/lib/railsbricks/assets/controllers/admin/devise_email/users_controller.rb +66 -0
  19. data/lib/railsbricks/assets/controllers/admin/devise_username/users_controller.rb +69 -0
  20. data/lib/railsbricks/assets/controllers/admin/posts_controller.rb +73 -0
  21. data/lib/railsbricks/assets/controllers/brick_contact.rbr +23 -0
  22. data/lib/railsbricks/assets/controllers/devise_email/application_controller.rb +54 -0
  23. data/lib/railsbricks/assets/controllers/devise_username/application_controller.rb +56 -0
  24. data/lib/railsbricks/assets/controllers/pages_controller.rb +13 -0
  25. data/lib/railsbricks/assets/controllers/posts_controller.rbr +10 -0
  26. data/lib/railsbricks/assets/database/postgresql.yml +12 -0
  27. data/lib/railsbricks/assets/database/sqlite3.yml +8 -0
  28. data/lib/railsbricks/assets/gemfile/Gemfile +44 -0
  29. data/lib/railsbricks/assets/git/gitignore +30 -0
  30. data/lib/railsbricks/assets/javascripts/analytics.js.coffee +5 -0
  31. data/lib/railsbricks/assets/lib/markdown_writer.rb +19 -0
  32. data/lib/railsbricks/assets/mailers/contact_mailer.rb +13 -0
  33. data/lib/railsbricks/assets/migrations/20141010133702_create_posts.rb +17 -0
  34. data/lib/railsbricks/assets/migrations/devise_email/20141010133701_devise_create_users.rb +48 -0
  35. data/lib/railsbricks/assets/migrations/devise_username/20141010133701_devise_create_users.rb +54 -0
  36. data/lib/railsbricks/assets/models/devise_email/user.rb +41 -0
  37. data/lib/railsbricks/assets/models/devise_username/user.rb +57 -0
  38. data/lib/railsbricks/assets/models/post.rb +30 -0
  39. data/lib/railsbricks/assets/procfile/Procfile +1 -0
  40. data/lib/railsbricks/assets/seeds/devise_email/seeds_no_test_users.rb +11 -0
  41. data/lib/railsbricks/assets/seeds/devise_email/seeds_test_users.rb +24 -0
  42. data/lib/railsbricks/assets/seeds/devise_username/seeds_no_test_users.rb +12 -0
  43. data/lib/railsbricks/assets/seeds/devise_username/seeds_test_users.rb +26 -0
  44. data/lib/railsbricks/assets/stylesheets/application.scss +6 -0
  45. data/lib/railsbricks/assets/stylesheets/railsbricks_custom.scss +562 -0
  46. data/lib/railsbricks/assets/views/admin/base/admin_posts_link.rbr +1 -0
  47. data/lib/railsbricks/assets/views/admin/base/devise_email/index.html.erb +41 -0
  48. data/lib/railsbricks/assets/views/admin/base/devise_username/index.html.erb +41 -0
  49. data/lib/railsbricks/assets/views/admin/posts/_form.html.erb +54 -0
  50. data/lib/railsbricks/assets/views/admin/posts/dashboard.html.erb +9 -0
  51. data/lib/railsbricks/assets/views/admin/posts/drafts.html.erb +23 -0
  52. data/lib/railsbricks/assets/views/admin/posts/edit.html.erb +10 -0
  53. data/lib/railsbricks/assets/views/admin/posts/index.html.erb +23 -0
  54. data/lib/railsbricks/assets/views/admin/posts/new.html.erb +6 -0
  55. data/lib/railsbricks/assets/views/admin/users/devise_email/edit.html.erb +65 -0
  56. data/lib/railsbricks/assets/views/admin/users/devise_email/index.html.erb +54 -0
  57. data/lib/railsbricks/assets/views/admin/users/devise_username/edit.html.erb +74 -0
  58. data/lib/railsbricks/assets/views/admin/users/devise_username/index.html.erb +56 -0
  59. data/lib/railsbricks/assets/views/contact_mailer/contact_message.html.erb +5 -0
  60. data/lib/railsbricks/assets/views/devise/allow_signup_links.rbr +11 -0
  61. data/lib/railsbricks/assets/views/devise/devise_email/confirmations/new.html.erb +31 -0
  62. data/lib/railsbricks/assets/views/devise/devise_email/mailer/confirmation_instructions.html.erb +12 -0
  63. data/lib/railsbricks/assets/views/devise/devise_email/mailer/reset_password_instructions.html.erb +15 -0
  64. data/lib/railsbricks/assets/views/devise/devise_email/passwords/edit.html.erb +43 -0
  65. data/lib/railsbricks/assets/views/devise/devise_email/passwords/new.html.erb +31 -0
  66. data/lib/railsbricks/assets/views/devise/devise_email/registrations/edit.html.erb +63 -0
  67. data/lib/railsbricks/assets/views/devise/devise_email/registrations/new.html.erb +49 -0
  68. data/lib/railsbricks/assets/views/devise/devise_email/sessions/new.html.erb +49 -0
  69. data/lib/railsbricks/assets/views/devise/devise_email/shared/_links.erb +19 -0
  70. data/lib/railsbricks/assets/views/devise/devise_username/confirmations/new.html.erb +31 -0
  71. data/lib/railsbricks/assets/views/devise/devise_username/mailer/confirmation_instructions.html.erb +12 -0
  72. data/lib/railsbricks/assets/views/devise/devise_username/mailer/reset_password_instructions.html.erb +15 -0
  73. data/lib/railsbricks/assets/views/devise/devise_username/passwords/edit.html.erb +43 -0
  74. data/lib/railsbricks/assets/views/devise/devise_username/passwords/new.html.erb +31 -0
  75. data/lib/railsbricks/assets/views/devise/devise_username/registrations/edit.html.erb +63 -0
  76. data/lib/railsbricks/assets/views/devise/devise_username/registrations/new.html.erb +58 -0
  77. data/lib/railsbricks/assets/views/devise/devise_username/sessions/new.html.erb +49 -0
  78. data/lib/railsbricks/assets/views/devise/devise_username/shared/_links.erb +19 -0
  79. data/lib/railsbricks/assets/views/layouts/_navigation_links.html.erb +15 -0
  80. data/lib/railsbricks/assets/views/layouts/brick_analytics.rbr +11 -0
  81. data/lib/railsbricks/assets/views/pages/contact.html.erb +46 -0
  82. data/lib/railsbricks/assets/views/pages/inside.html.erb +4 -0
  83. data/lib/railsbricks/assets/views/pages/posts.html.erb +18 -0
  84. data/lib/railsbricks/assets/views/pages/show_post.html.erb +6 -0
  85. data/lib/railsbricks/auth_builder.rb +147 -0
  86. data/lib/railsbricks/config_helpers.rb +27 -0
  87. data/lib/railsbricks/config_values.rb +14 -0
  88. data/lib/railsbricks/errors.rb +18 -0
  89. data/lib/railsbricks/file_helpers.rb +54 -0
  90. data/lib/railsbricks/foundation/README.md +24 -0
  91. data/lib/railsbricks/foundation/Rakefile +6 -0
  92. data/lib/railsbricks/foundation/app/assets/images/.keep +0 -0
  93. data/lib/railsbricks/foundation/app/assets/images/apple-touch-icon-precomposed.png +0 -0
  94. data/lib/railsbricks/foundation/app/assets/images/apple-touch-icon.png +0 -0
  95. data/lib/railsbricks/foundation/app/assets/images/favicon.ico +0 -0
  96. data/lib/railsbricks/foundation/app/assets/javascripts/application.js +17 -0
  97. data/lib/railsbricks/foundation/app/assets/javascripts/common.js +7 -0
  98. data/lib/railsbricks/foundation/app/controllers/application_controller.rb +5 -0
  99. data/lib/railsbricks/foundation/app/controllers/concerns/.keep +0 -0
  100. data/lib/railsbricks/foundation/app/controllers/pages_controller.rb +7 -0
  101. data/lib/railsbricks/foundation/app/helpers/application_helper.rb +7 -0
  102. data/lib/railsbricks/foundation/app/helpers/email_helper.rb +5 -0
  103. data/lib/railsbricks/foundation/app/mailers/.keep +0 -0
  104. data/lib/railsbricks/foundation/app/models/.keep +0 -0
  105. data/lib/railsbricks/foundation/app/models/concerns/.keep +0 -0
  106. data/lib/railsbricks/foundation/app/views/layouts/_footer.html.erb +18 -0
  107. data/lib/railsbricks/foundation/app/views/layouts/_messages.html.erb +9 -0
  108. data/lib/railsbricks/foundation/app/views/layouts/_navigation.html.erb +18 -0
  109. data/lib/railsbricks/foundation/app/views/layouts/_navigation_links.html.erb +3 -0
  110. data/lib/railsbricks/foundation/app/views/layouts/application.html.erb +38 -0
  111. data/lib/railsbricks/foundation/app/views/pages/home.html.erb +2 -0
  112. data/lib/railsbricks/foundation/bin/bundle +3 -0
  113. data/lib/railsbricks/foundation/bin/rails +4 -0
  114. data/lib/railsbricks/foundation/bin/rake +4 -0
  115. data/lib/railsbricks/foundation/config.ru +4 -0
  116. data/lib/railsbricks/foundation/config/application.rb +34 -0
  117. data/lib/railsbricks/foundation/config/boot.rb +4 -0
  118. data/lib/railsbricks/foundation/config/environment.rb +5 -0
  119. data/lib/railsbricks/foundation/config/environments/development.rb +41 -0
  120. data/lib/railsbricks/foundation/config/environments/production.rb +95 -0
  121. data/lib/railsbricks/foundation/config/environments/test.rb +51 -0
  122. data/lib/railsbricks/foundation/config/initializers/backtrace_silencers.rb +7 -0
  123. data/lib/railsbricks/foundation/config/initializers/date_format.rb +27 -0
  124. data/lib/railsbricks/foundation/config/initializers/filter_parameter_logging.rb +4 -0
  125. data/lib/railsbricks/foundation/config/initializers/friendly_id.rb +88 -0
  126. data/lib/railsbricks/foundation/config/initializers/inflections.rb +16 -0
  127. data/lib/railsbricks/foundation/config/initializers/kaminari_config.rb +10 -0
  128. data/lib/railsbricks/foundation/config/initializers/mime_types.rb +5 -0
  129. data/lib/railsbricks/foundation/config/initializers/secret_token.rb +25 -0
  130. data/lib/railsbricks/foundation/config/initializers/session_store.rb +3 -0
  131. data/lib/railsbricks/foundation/config/initializers/wrap_parameters.rb +14 -0
  132. data/lib/railsbricks/foundation/config/locales/en.yml +23 -0
  133. data/lib/railsbricks/foundation/config/routes.rb +7 -0
  134. data/lib/railsbricks/foundation/db/migrate/20131103142222_create_friendly_id_slugs.rb +15 -0
  135. data/lib/railsbricks/foundation/db/schema.rb +29 -0
  136. data/lib/railsbricks/foundation/db/seeds.rb +0 -0
  137. data/lib/railsbricks/foundation/lib/assets/.keep +0 -0
  138. data/lib/railsbricks/foundation/lib/tasks/.keep +0 -0
  139. data/lib/railsbricks/foundation/public/404.html +58 -0
  140. data/lib/railsbricks/foundation/public/422.html +58 -0
  141. data/lib/railsbricks/foundation/public/500.html +57 -0
  142. data/lib/railsbricks/foundation/public/favicon.ico +0 -0
  143. data/lib/railsbricks/foundation/public/robots.txt +5 -0
  144. data/lib/railsbricks/foundation/vendor/assets/javascripts/.keep +0 -0
  145. data/lib/railsbricks/foundation/vendor/assets/stylesheets/.keep +0 -0
  146. data/lib/railsbricks/gemfile_builder.rb +118 -0
  147. data/lib/railsbricks/menu.rb +533 -0
  148. data/lib/railsbricks/post_builder.rb +103 -0
  149. data/lib/railsbricks/string_helpers.rb +39 -0
  150. data/lib/railsbricks/style_builder.rb +97 -0
  151. data/lib/railsbricks/ui_helpers.rb +11 -0
  152. data/lib/railsbricks/validator.rb +68 -0
  153. data/lib/railsbricks/version.rb +34 -0
  154. data/railsbricks.gemspec +16 -0
  155. metadata +198 -0
@@ -0,0 +1,8 @@
1
+ # SQLite version 3.x
2
+ # Ensure the SQLite 3 gem is defined in your Gemfile
3
+ # gem 'sqlite3'
4
+ development:
5
+ adapter: sqlite3
6
+ database: db/development.sqlite3
7
+ pool: 5
8
+ timeout: 5000
@@ -0,0 +1,44 @@
1
+ source 'https://rubygems.org'
2
+ ruby 'BRICK_RUBY_VERSION'
3
+
4
+ # Standard Rails gems
5
+ gem 'rails', 'BRICK_RAILS_VERSION'
6
+ gem 'sass-rails', 'BRICK_SASS_RAILS_VERSION'
7
+ gem 'uglifier', 'BRICK_UGLIFIER_VERSION'
8
+ gem 'coffee-rails', 'BRICK_COFFEE_RAILS_VERSION'
9
+ gem 'jquery-rails', 'BRICK_JQUERY_RAILS_VERSION'
10
+ gem 'turbolinks', 'BRICK_TURBOLINKS_VERSION'
11
+ gem 'jbuilder', 'BRICK_JBUILDER_VERSION'
12
+ gem 'bcrypt', 'BRICK_BCRYPT_VERSION'
13
+
14
+ # Necessary for Windows OS (won't install on *nix systems)
15
+ gem 'tzinfo-data', platforms: [:mingw, :mswin]
16
+
17
+ # Kaminari: https://github.com/amatsuda/kaminari
18
+ gem 'kaminari', 'BRICK_KAMINARI_VERSION'
19
+
20
+ # Friendly_id: https://github.com/norman/friendly_id
21
+ gem 'friendly_id', 'BRICK_FRIENDLY_ID_VERSION'
22
+
23
+ # Font-awesome: https://github.com/FortAwesome/font-awesome-sass
24
+ gem 'font-awesome-sass', 'BRICK_FONT_AWESOME_SASS_VERSION'
25
+
26
+ # RailsBricks: http://www.railsbricks.net
27
+ gem 'railsbricks'
28
+
29
+ # Bootstrap 3: https://github.com/twbs/bootstrap-sass
30
+ gem 'bootstrap-sass', 'BRICK_BOOTSTRAP_SASS_VERSION'
31
+
32
+ group :development, :test do
33
+ gem 'byebug', 'BRICK_BYEBUG_VERSION'
34
+ gem 'web-console', 'BRICK_WEB_CONSOLE_VERSION'
35
+
36
+ # Figaro: https://github.com/laserlemon/figaro
37
+ gem 'figaro', 'BRICK_FIGARO_VERSION'
38
+
39
+ # Spring: https://github.com/rails/spring
40
+ gem 'spring', 'BRICK_SPRING_VERSION'
41
+
42
+ # Annotate_Models: https://github.com/ctran/annotate_models
43
+ gem 'annotate', 'BRICK_ANNOTATE_VERSION'
44
+ end
@@ -0,0 +1,30 @@
1
+ # generated by RailsBricks
2
+
3
+ # Don't ignore bundler config!
4
+ # Useful when git cloning an app and not wanting
5
+ # the gems to be installed globally.
6
+ # Can be uncommented if really necessary.
7
+ # /.bundle
8
+
9
+ # Ignore the bundle directory itself.
10
+ /vendor/bundle
11
+
12
+ # Ignore the default SQLite database.
13
+ /db/*.sqlite3
14
+ /db/*.sqlite3-journal
15
+
16
+ # Ignore all logfiles and tempfiles.
17
+ /log/*.log
18
+ /tmp
19
+
20
+ # Ignore other unneeded files.
21
+ doc/
22
+ *.swp
23
+ *~
24
+ .project
25
+ .DS_Store
26
+ .idea
27
+
28
+ # Ignore application configuration
29
+ /config/application.yml
30
+ .secret
@@ -0,0 +1,5 @@
1
+ $(document).on 'page:change', ->
2
+ if window._gaq?
3
+ _gaq.push ['_trackPageview']
4
+ else if window.pageTracker?
5
+ pageTracker._trackPageview()
@@ -0,0 +1,19 @@
1
+ # Documentation for RedCarpet: https://github.com/vmg/redcarpet
2
+ class MarkdownWriter
3
+
4
+ def self.to_html(markdown)
5
+ renderer = Redcarpet::Render::HTML.new(filter_html: false,
6
+ no_styles: true,
7
+ no_images: false,
8
+ with_toc_data: false,
9
+ link_attributes: {:target => "_blank"}
10
+ )
11
+ converter = Redcarpet::Markdown.new(renderer)
12
+ output = converter.render(markdown)
13
+ end
14
+
15
+ def self.update_html(obj)
16
+ obj.content_html = MarkdownWriter.to_html(obj.content_md)
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ class ContactMailer < ActionMailer::Base
2
+ add_template_helper(EmailHelper)
3
+ default from: ENV["SENDER_EMAIL"]
4
+
5
+
6
+ def contact_message(name, email, message)
7
+ @name = name
8
+ @email = email
9
+ @message = message
10
+
11
+ mail to: ENV["SENDER_EMAIL"], subject: "New message received at #{ENV["DOMAIN"]}"
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content_md
6
+ t.text :content_html
7
+ t.boolean :draft, default: false
8
+ t.integer :user_id
9
+
10
+ # FriendlyId
11
+ t.string :slug
12
+
13
+ t.timestamps
14
+ end
15
+ add_index :posts, :user_id
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Admin
9
+ t.boolean :admin, :null => false, :default => false
10
+
11
+ ## Lock
12
+ t.boolean :locked, :null => false, :default => false
13
+
14
+ ## Recoverable
15
+ t.string :reset_password_token
16
+ t.datetime :reset_password_sent_at
17
+
18
+ ## Rememberable
19
+ t.datetime :remember_created_at
20
+
21
+ ## Trackable
22
+ t.integer :sign_in_count, :default => 0, :null => false
23
+ t.datetime :current_sign_in_at
24
+ t.datetime :last_sign_in_at
25
+ t.string :current_sign_in_ip
26
+ t.string :last_sign_in_ip
27
+
28
+ ## Confirmable
29
+ t.string :confirmation_token
30
+ t.datetime :confirmed_at
31
+ t.datetime :confirmation_sent_at
32
+ t.string :unconfirmed_email # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
36
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
37
+ # t.datetime :locked_at
38
+
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ add_index :users, :email, :unique => true
44
+ add_index :users, :reset_password_token, :unique => true
45
+ add_index :users, :confirmation_token, :unique => true
46
+ # add_index :users, :unlock_token, :unique => true
47
+ end
48
+ end
@@ -0,0 +1,54 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :username, :null => false, :default => ""
6
+ t.string :email, :null => false, :default => ""
7
+ t.string :encrypted_password, :null => false, :default => ""
8
+
9
+ ## Admin
10
+ t.boolean :admin, :null => false, :default => false
11
+
12
+ ## Lock
13
+ t.boolean :locked, :null => false, :default => false
14
+
15
+ ## Friendly_id
16
+ t.string :slug
17
+
18
+ ## Recoverable
19
+ t.string :reset_password_token
20
+ t.datetime :reset_password_sent_at
21
+
22
+ ## Rememberable
23
+ t.datetime :remember_created_at
24
+
25
+ ## Trackable
26
+ t.integer :sign_in_count, :default => 0, :null => false
27
+ t.datetime :current_sign_in_at
28
+ t.datetime :last_sign_in_at
29
+ t.string :current_sign_in_ip
30
+ t.string :last_sign_in_ip
31
+
32
+ ## Confirmable
33
+ t.string :confirmation_token
34
+ t.datetime :confirmed_at
35
+ t.datetime :confirmation_sent_at
36
+ t.string :unconfirmed_email # Only if using reconfirmable
37
+
38
+ ## Lockable
39
+ # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
40
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
41
+ # t.datetime :locked_at
42
+
43
+
44
+ t.timestamps
45
+ end
46
+
47
+ add_index :users, :username, :unique => true
48
+ add_index :users, :email, :unique => true
49
+ add_index :users, :reset_password_token, :unique => true
50
+ add_index :users, :confirmation_token, :unique => true
51
+ add_index :users, :slug, :unique => true
52
+ # add_index :users, :unlock_token, :unique => true
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ class User < ActiveRecord::Base
2
+ BRICK_POSTS_RELATION
3
+ # Include default devise modules. Others available are:
4
+ # :confirmable, :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable, BRICK_ALLOW_SIGNUP
6
+ :recoverable, :rememberable, :trackable, :validatable, :confirmable
7
+
8
+ # Pagination
9
+ paginates_per 100
10
+
11
+ # Validations
12
+ # :email
13
+ validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
14
+
15
+ def self.paged(page_number)
16
+ order(admin: :desc, email: :asc).page page_number
17
+ end
18
+
19
+ def self.search_and_order(search, page_number)
20
+ if search
21
+ where("email LIKE ?", "%#{search.downcase}%").order(
22
+ admin: :desc, email: :asc
23
+ ).page page_number
24
+ else
25
+ order(admin: :desc, email: :asc).page page_number
26
+ end
27
+ end
28
+
29
+ def self.last_signups(count)
30
+ order(created_at: :desc).limit(count).select("id","email","created_at")
31
+ end
32
+
33
+ def self.last_signins(count)
34
+ order(last_sign_in_at:
35
+ :desc).limit(count).select("id","email","last_sign_in_at")
36
+ end
37
+
38
+ def self.users_count
39
+ where("admin = ? AND locked = ?",false,false).count
40
+ end
41
+ end
@@ -0,0 +1,57 @@
1
+ class User < ActiveRecord::Base
2
+ # Use friendly_id on Users
3
+ extend FriendlyId
4
+ friendly_id :friendify, use: :slugged
5
+
6
+ # necessary to override friendly_id reserved words
7
+ def friendify
8
+ if username.downcase == "admin"
9
+ "user-#{username}"
10
+ else
11
+ "#{username}"
12
+ end
13
+ end
14
+ BRICK_POSTS_RELATION
15
+ # Include default devise modules. Others available are:
16
+ # :confirmable, :lockable, :timeoutable and :omniauthable
17
+ devise :database_authenticatable, BRICK_ALLOW_SIGNUP
18
+ :recoverable, :rememberable, :trackable, :validatable, :confirmable
19
+
20
+ # Pagination
21
+ paginates_per 100
22
+
23
+ # Validations
24
+ # :username
25
+ validates :username, uniqueness: { case_sensitive: false }
26
+ validates_format_of :username, with: /\A[a-zA-Z0-9]*\z/, on: :create, message: "can only contain letters and digits"
27
+ validates :username, length: { in: 4..15 }
28
+ # :email
29
+ validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
30
+
31
+ def self.paged(page_number)
32
+ order(admin: :desc, username: :asc).page page_number
33
+ end
34
+
35
+ def self.search_and_order(search, page_number)
36
+ if search
37
+ where("username LIKE ?", "%#{search.downcase}%").order(
38
+ admin: :desc, username: :asc
39
+ ).page page_number
40
+ else
41
+ order(admin: :desc, username: :asc).page page_number
42
+ end
43
+ end
44
+
45
+ def self.last_signups(count)
46
+ order(created_at: :desc).limit(count).select("id","username","slug","created_at")
47
+ end
48
+
49
+ def self.last_signins(count)
50
+ order(last_sign_in_at:
51
+ :desc).limit(count).select("id","username","slug","last_sign_in_at")
52
+ end
53
+
54
+ def self.users_count
55
+ where("admin = ? AND locked = ?",false,false).count
56
+ end
57
+ end
@@ -0,0 +1,30 @@
1
+ class Post < ActiveRecord::Base
2
+ # Use friendly_id
3
+ extend FriendlyId
4
+ friendly_id :title, use: :slugged
5
+
6
+ # Markdown
7
+ before_save { MarkdownWriter.update_html(self) }
8
+
9
+ # Validations
10
+ validates :title, presence: true, length: { maximum: 100 }, uniqueness: true
11
+ validates :content_md, presence: true
12
+
13
+ # Pagination
14
+ paginates_per 30
15
+
16
+ # Relations
17
+ belongs_to :user
18
+
19
+ # Scopes
20
+ scope :published, lambda {
21
+ where(draft: false)
22
+ .order("updated_at DESC")
23
+ }
24
+
25
+ scope :drafted, lambda {
26
+ where(draft: true)
27
+ .order("updated_at DESC")
28
+ }
29
+
30
+ end
@@ -0,0 +1 @@
1
+ web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
@@ -0,0 +1,11 @@
1
+ # Generated with RailsBricks
2
+ # Initial seed file to use with Devise User Model
3
+
4
+ # Temporary admin account
5
+ u = User.new(
6
+ email: "admin@example.com",
7
+ password: "1234",
8
+ admin: true
9
+ )
10
+ u.skip_confirmation!
11
+ u.save!
@@ -0,0 +1,24 @@
1
+ # Generated with RailsBricks
2
+ # Initial seed file to use with Devise User Model
3
+
4
+ # Temporary admin account
5
+ u = User.new(
6
+ email: "admin@example.com",
7
+ password: "1234",
8
+ admin: true
9
+ )
10
+ u.skip_confirmation!
11
+ u.save!
12
+
13
+ # Test user accounts
14
+ (1..50).each do |i|
15
+ u = User.new(
16
+ email: "user#{i}@example.com",
17
+ password: "1234"
18
+ )
19
+ u.skip_confirmation!
20
+ u.save!
21
+
22
+ puts "#{i} test users created..." if (i % 5 == 0)
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ # Generated with RailsBricks
2
+ # Initial seed file to use with Devise User Model
3
+
4
+ # Temporary admin account
5
+ u = User.new(
6
+ username: "admin",
7
+ email: "admin@example.com",
8
+ password: "1234",
9
+ admin: true
10
+ )
11
+ u.skip_confirmation!
12
+ u.save!
@@ -0,0 +1,26 @@
1
+ # Generated with RailsBricks
2
+ # Initial seed file to use with Devise User Model
3
+
4
+ # Temporary admin account
5
+ u = User.new(
6
+ username: "admin",
7
+ email: "admin@example.com",
8
+ password: "1234",
9
+ admin: true
10
+ )
11
+ u.skip_confirmation!
12
+ u.save!
13
+
14
+ # Test user accounts
15
+ (1..50).each do |i|
16
+ u = User.new(
17
+ username: "user#{i}",
18
+ email: "user#{i}@example.com",
19
+ password: "1234"
20
+ )
21
+ u.skip_confirmation!
22
+ u.save!
23
+
24
+ puts "#{i} test users created..." if (i % 5 == 0)
25
+
26
+ end