Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from korny/version-2

Version 2
  • Loading branch information...
commit f79020594aac743f3169832942efdd9e169a8fb8 2 parents 174c27c + 3530f5d
@korny authored
Showing with 347 additions and 154 deletions.
  1. +1 −1  .ruby-version
  2. +3 −0  Capfile
  3. +5 −4 Gemfile
  4. +84 −89 Gemfile.lock
  5. +1 −1  app/assets/javascripts/application.js
  6. +26 −4 app/assets/javascripts/sidebar.js.coffee
  7. +3 −0  app/assets/stylesheets/login.css.sass
  8. +26 −1 app/assets/stylesheets/sidebar.css.sass
  9. +4 −7 app/controllers/images_controller.rb
  10. +21 −7 app/controllers/pages_controller.rb
  11. +37 −0 app/controllers/sections_controller.rb
  12. +1 −1  app/helpers/markup_helper.rb
  13. +26 −4 app/models/concerns/order_by_position.rb
  14. +1 −1  app/models/concerns/url_title.rb
  15. +7 −1 app/models/image.rb
  16. +18 −9 app/models/page.rb
  17. +11 −1 app/models/section.rb
  18. +19 −12 app/views/layouts/_sidebar.html.haml
  19. +3 −0  app/views/layouts/_sidebar_add_page.html.haml
  20. +13 −0 app/views/layouts/_sidebar_page.html.haml
  21. +1 −0  app/views/pages/create.js.erb
  22. +1 −0  app/views/pages/destroy.js.erb
  23. +1 −0  app/views/pages/update.js.erb
  24. +5 −2 config/deploy.rb
  25. +5 −5 config/routes.rb
  26. +1 −1  lib/assets/javascripts/jquery_ujs.prompt.js.coffee
  27. +23 −3 lib/tasks/setup.rake
View
2  .ruby-version
@@ -1 +1 @@
-ruby-2.1.0
+ruby-2.1
View
3  Capfile
@@ -4,6 +4,9 @@ require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
+# RVM integration
+require 'rvm1/capistrano3'
+
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
View
9 Gemfile
@@ -1,19 +1,19 @@
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
-gem 'rails', '4.1.0'
+gem 'rails', '~> 4.1.9'
# Use MySQL as the database for Active Record
gem 'mysql2'
# Use Sass for stylesheets
-gem 'sass-rails', :github => 'rails/sass-rails'
+gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
-gem 'coffee-rails', '~> 4.0.0'
+gem 'coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
@@ -48,10 +48,11 @@ gem 'paperclip'
gem 'haml'
# Use kramdown for Markdown
-gem 'kramdown'
+gem 'rdiscount'
# Use Capistrano for deployment
gem 'capistrano-rails', require: false, group: :development
+gem 'rvm1-capistrano3', require: false
# Silence asset logging
gem 'quiet_assets', group: :development
View
173 Gemfile.lock
@@ -1,153 +1,147 @@
-GIT
- remote: git://github.com/rails/sass-rails.git
- revision: 7138bbb401159b116dda4ec9dd4b375dc1d2e59a
- specs:
- sass-rails (4.0.1)
- railties (>= 4.0.0, < 5.0)
- sass (~> 3.2.0)
- sprockets (~> 2.8, <= 2.11.0)
- sprockets-rails (~> 2.0)
-
GEM
remote: https://rubygems.org/
specs:
- actionmailer (4.1.0)
- actionpack (= 4.1.0)
- actionview (= 4.1.0)
- mail (~> 2.5.4)
- actionpack (4.1.0)
- actionview (= 4.1.0)
- activesupport (= 4.1.0)
+ actionmailer (4.1.9)
+ actionpack (= 4.1.9)
+ actionview (= 4.1.9)
+ mail (~> 2.5, >= 2.5.4)
+ actionpack (4.1.9)
+ actionview (= 4.1.9)
+ activesupport (= 4.1.9)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
- actionview (4.1.0)
- activesupport (= 4.1.0)
+ actionview (4.1.9)
+ activesupport (= 4.1.9)
builder (~> 3.1)
erubis (~> 2.7.0)
- activemodel (4.1.0)
- activesupport (= 4.1.0)
+ activemodel (4.1.9)
+ activesupport (= 4.1.9)
builder (~> 3.1)
- activerecord (4.1.0)
- activemodel (= 4.1.0)
- activesupport (= 4.1.0)
+ activerecord (4.1.9)
+ activemodel (= 4.1.9)
+ activesupport (= 4.1.9)
arel (~> 5.0.0)
- activesupport (4.1.0)
+ activesupport (4.1.9)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
- bcrypt (3.1.7)
+ bcrypt (3.1.9)
builder (3.2.2)
- capistrano (3.2.0)
+ capistrano (3.3.5)
+ capistrano-stats (~> 1.1.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
- capistrano-bundler (1.1.2)
- capistrano (~> 3.0)
+ capistrano-bundler (1.1.3)
+ capistrano (~> 3.1)
sshkit (~> 1.2)
- capistrano-rails (1.1.1)
+ capistrano-rails (1.1.2)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
+ capistrano-stats (1.1.1)
climate_control (0.0.3)
activesupport (>= 3.0)
- cocaine (0.5.4)
+ cocaine (0.5.5)
climate_control (>= 0.0.3, < 1.0)
- coffee-rails (4.0.1)
+ coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
- coffee-script (2.2.0)
+ coffee-script (2.3.0)
coffee-script-source
execjs
- coffee-script-source (1.7.0)
+ coffee-script-source (1.8.0)
+ colorize (0.7.5)
erubis (2.7.0)
- execjs (2.0.2)
- haml (4.0.5)
+ execjs (2.2.2)
+ haml (4.0.6)
tilt
hike (1.2.3)
- i18n (0.6.9)
- jquery-rails (3.1.0)
+ i18n (0.7.0)
+ jquery-rails (3.1.2)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
- jquery-turbolinks (2.0.2)
+ jquery-turbolinks (2.1.0)
railties (>= 3.1.0)
turbolinks
- jquery-ui-rails (4.2.1)
+ jquery-ui-rails (5.0.3)
railties (>= 3.2.16)
- json (1.8.1)
- kramdown (1.3.3)
- libv8 (3.16.14.3)
- mail (2.5.4)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
- mime-types (1.25.1)
- minitest (5.3.3)
- multi_json (1.9.2)
- mysql2 (0.3.15)
- net-scp (1.2.0)
+ json (1.8.2)
+ libv8 (3.16.14.7)
+ mail (2.6.3)
+ mime-types (>= 1.16, < 3)
+ mime-types (2.4.3)
+ minitest (5.5.1)
+ multi_json (1.10.1)
+ mysql2 (0.3.17)
+ net-scp (1.2.1)
net-ssh (>= 2.6.5)
- net-ssh (2.8.0)
- paperclip (4.1.1)
+ net-ssh (2.9.2)
+ paperclip (4.2.1)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
- polyglot (0.3.4)
- quiet_assets (1.0.2)
+ quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.5.2)
- rack-test (0.6.2)
+ rack-test (0.6.3)
rack (>= 1.0)
- rails (4.1.0)
- actionmailer (= 4.1.0)
- actionpack (= 4.1.0)
- actionview (= 4.1.0)
- activemodel (= 4.1.0)
- activerecord (= 4.1.0)
- activesupport (= 4.1.0)
+ rails (4.1.9)
+ actionmailer (= 4.1.9)
+ actionpack (= 4.1.9)
+ actionview (= 4.1.9)
+ activemodel (= 4.1.9)
+ activerecord (= 4.1.9)
+ activesupport (= 4.1.9)
bundler (>= 1.3.0, < 2.0)
- railties (= 4.1.0)
+ railties (= 4.1.9)
sprockets-rails (~> 2.0)
- railties (4.1.0)
- actionpack (= 4.1.0)
- activesupport (= 4.1.0)
+ railties (4.1.9)
+ actionpack (= 4.1.9)
+ activesupport (= 4.1.9)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
- rake (10.3.1)
+ rake (10.4.2)
+ rdiscount (2.1.7.1)
ref (1.0.5)
- sass (3.2.19)
- spring (1.1.2)
- sprockets (2.11.0)
+ rvm1-capistrano3 (1.3.2.2)
+ capistrano (~> 3.0)
+ sshkit (>= 1.2)
+ sass (3.4.9)
+ sass-rails (5.0.1)
+ railties (>= 4.0.0, < 5.0)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (~> 1.1)
+ spring (1.2.0)
+ sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sprockets-rails (2.1.3)
+ sprockets-rails (2.2.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
- sprockets (~> 2.8)
- sshkit (1.4.0)
+ sprockets (>= 2.8, < 4.0)
+ sshkit (1.6.1)
+ colorize (>= 0.7.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
- term-ansicolor
- term-ansicolor (1.3.0)
- tins (~> 1.0)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
- thread_safe (0.3.3)
+ thread_safe (0.3.4)
tilt (1.4.1)
- tins (1.1.0)
- treetop (1.4.15)
- polyglot
- polyglot (>= 0.3.1)
- turbolinks (2.2.2)
+ turbolinks (2.5.3)
coffee-rails
- tzinfo (1.1.0)
+ tzinfo (1.2.2)
thread_safe (~> 0.1)
- uglifier (2.5.0)
+ uglifier (2.7.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
@@ -157,17 +151,18 @@ PLATFORMS
DEPENDENCIES
bcrypt (~> 3.1.7)
capistrano-rails
- coffee-rails (~> 4.0.0)
+ coffee-rails
haml
jquery-rails
jquery-turbolinks
jquery-ui-rails
- kramdown
mysql2
paperclip
quiet_assets
- rails (= 4.1.0)
- sass-rails!
+ rails (~> 4.1.9)
+ rdiscount
+ rvm1-capistrano3
+ sass-rails
spring
therubyracer
turbolinks
View
2  app/assets/javascripts/application.js
@@ -12,7 +12,7 @@
//
//= require jquery
//= require jquery.turbolinks
-//= require jquery.ui.sortable
+//= require jquery-ui/sortable
//= require jquery_ujs
//= require jquery.fancybox
//= require jquery_ujs.prompt
View
30 app/assets/javascripts/sidebar.js.coffee
@@ -1,7 +1,29 @@
-# disabled for now
-->
+$ ->
# reorder sections
- $('.sidebar').sortable()
+ if sortUpdateURL = $('.sidebar').data('sort-update-url')
+ $('.sidebar').sortable
+ axis: 'y'
+ update: ->
+ ids = $('> *', @).map -> $(@).data('id')
+ $.ajax
+ type: 'PATCH',
+ url: sortUpdateURL,
+ data: { ids: ids.get() }
+ null
+$ ->
# reorder pages
- $('.section ul').sortable()
+ $('.section ul[data-sort-update-url]').each ->
+ sortUpdateURL = $(@).data('sort-update-url')
+ $(@).sortable
+ items: 'li[data-id]'
+ axis: 'y'
+ containment: 'parent'
+ tolerance: 'pointer'
+ update: ->
+ ids = $('> *', @).map -> $(@).data('id')
+ $.ajax
+ type: 'PATCH',
+ url: sortUpdateURL,
+ data: { ids: ids.get() }
+ null
View
3  app/assets/stylesheets/login.css.sass
@@ -5,6 +5,9 @@
top: 0
margin: 5px
+a.logout
+ color: #666
+
$login-transition: width 0.4s ease, border-color 0.4s ease, color 0.4s ease
.login input
View
27 app/assets/stylesheets/sidebar.css.sass
@@ -12,13 +12,38 @@ ul.sidebar
background-color: white
> li
- margin-bottom: 12px
+ padding-bottom: 12px
&, & ul
list-style-type: none
& ul
padding-left: 0
+ .admin, .empty-section-title
+ display: none
+ li.page:hover .admin
+ display: inline
+ li.section:hover > .admin
+ display: inline
+ &:hover
+ .add-section, .empty-section-title
+ display: inline
+
+ .admin
+ color: gray
+ &:hover
+ color: black
+
+ .section-title
+ color: #666
+
+ .current
+ color: black
+ font-size: 20px
+
+ .content
margin-left: $sidebar-width + 10px
margin-top: $sidebar-top + 5px
+
+ul.ui-sortable > li[data-id]
+ cursor: move
View
11 app/controllers/images_controller.rb
@@ -1,7 +1,7 @@
class ImagesController < ApplicationController
- before_action :set_section, only: [:create, :reorder]
- before_action :set_page, only: [:create, :reorder]
- before_action :set_image, only: [:update, :destroy]
+ before_action :set_section, only: [:create, :reorder]
+ before_action :set_page, only: [:create, :reorder]
+ before_action :set_image, except: [:create, :reorder]
def create
image = @page.images.build
@@ -12,10 +12,7 @@ def create
end
def reorder
- ids = params[:ids].map(&:to_i).uniq
- if ids.size == @page.images.size
- @page.update_images_order ids
- end
+ @page.images.update_order params[:ids].map(&:to_i)
head :ok
end
View
28 app/controllers/pages_controller.rb
@@ -1,8 +1,8 @@
class PagesController < ApplicationController
- skip_before_filter :login_required
+ skip_before_filter :login_required, only: [:index, :show]
- before_action :set_section, :only => [:show, :update]
- before_action :set_page, :only => [:show, :update]
+ before_action :set_section, except: :index
+ before_action :set_page, only: [:show, :update, :destroy]
def index
@section = Section.welcome_section
@@ -14,16 +14,30 @@ def index
def show
end
- def update
- @page.update! page_params
+ def create
+ @page = @section.pages.create!(page_params)
+ end
+
+ def reorder
+ @section.pages.update_order params[:ids].map(&:to_i)
- reload_page
+ head :ok
+ end
+
+ def update
+ @page.update!(page_params)
+ end
+
+ def destroy
+ @page.destroy!
end
private
def set_section
@section = Section.find_by!(url_title: params[:section_id])
+ rescue
+ redirect_to root_url
end
def set_page
@@ -31,7 +45,7 @@ def set_page
end
def page_params
- params.require(:page).permit(:images_zoom_factor, :text).tap do |page_params|
+ params.require(:page).permit(:title, :images_zoom_factor, :text).tap do |page_params|
page_params[:text].encode! universal_newline: true if page_params[:text]
end
end
View
37 app/controllers/sections_controller.rb
@@ -0,0 +1,37 @@
+class SectionsController < ApplicationController
+ before_filter :set_section, except: [:create, :reorder]
+
+ def create
+ Section.create!(section_params)
+
+ reload_page
+ end
+
+ def reorder
+ Section.update_order params[:ids].map(&:to_i)
+
+ head :ok
+ end
+
+ def update
+ @section.update!(section_params)
+
+ reload_page
+ end
+
+ def destroy
+ @section.destroy
+
+ reload_page
+ end
+
+ private
+
+ def set_section
+ @section = Section.find_by!(url_title: params[:id])
+ end
+
+ def section_params
+ params.require(:section).permit(:title)
+ end
+end
View
2  app/helpers/markup_helper.rb
@@ -1,5 +1,5 @@
module MarkupHelper
def markdown text
- text.blank? ? '' : Kramdown::Document.new(text.gsub(/(?<!\n)\n(?!\n)/, "\n<br>")).to_html.html_safe
+ text.blank? ? '' : RDiscount.new(text).to_html.html_safe
end
end
View
30 app/models/concerns/order_by_position.rb
@@ -4,16 +4,38 @@ module OrderByPosition
included do
default_scope { order(:position) }
- before_validation :set_position
+ validates :position, presence: true, numericality: true, allow_nil: true
- validates :position, presence: true, numericality: true
+ after_destroy :cleanup_positions
+ end
+
+ module ClassMethods
+ def update_order ids
+ if ids.size == count
+ ids.each_with_index do |id, index|
+ where(:id => id).update_all ['position = ?', index + 1]
+ end
+ else
+ raise 'number of given ids differs from records to order: %p != %p' % [ids.size, count]
+ end
+ end
end
protected
- def set_position
+ def set_top_position
+ order_scope.try(:update_all, 'position = position + 1')
+
+ self.position = 1
+ end
+
+ def set_bottom_position
if siblings = order_scope
- self.position ||= (siblings.maximum(:position) || 0) + 1
+ self.position = (siblings.maximum(:position) || 0) + 1
end
end
+
+ def cleanup_positions
+ order_scope.try(:update_order, order_scope.ids)
+ end
end
View
2  app/models/concerns/url_title.rb
@@ -18,7 +18,7 @@ def to_param
protected
def set_url_title
- self.url_title ||= unique_url_title(title.parameterize) if title?
+ self.url_title = unique_url_title(title.parameterize) if title? && (title_changed? || url_title.blank?)
end
def unique_url_title title
View
8 app/models/image.rb
@@ -25,10 +25,16 @@ class Image < ActiveRecord::Base
before_validation :set_url_title_from_filename, if: :picture?, on: :create
+ before_create :set_bottom_position
+
after_save -> { reload.reprocess_picture! }, if: :long_side_changed?
+ def zoom_factor
+ page.images_zoom_factor / 100.0
+ end
+
def size_for_thumbnail
- (long_side * (page.images_zoom_factor / 100.0)).round
+ (long_side * zoom_factor).round
end
def reprocess_picture!
View
27 app/models/page.rb
@@ -13,24 +13,33 @@ class Page < ActiveRecord::Base
validates_url_title_unique scope: [:section_id]
- after_save :reprocess_images!, if: :images_zoom_factor_changed?
+ after_initialize :set_title
- def update_images_order image_ids
- transaction do
- image_ids.each_with_index do |id, index|
- Image.where(:id => id).update_all ['position = ?', index + 1]
- end
- touch
- end
+ before_create :set_top_position
+
+ after_commit :reprocess_images!, if: -> { previous_changes.key? :images_zoom_factor }
+
+ def can_be_deleted?
+ images.empty? && text.blank?
end
protected
+ def set_title
+ self.title ||= Date.today.year.to_s
+ end
+
def order_scope
section.try(:pages)
end
def reprocess_images!
- images.each(&:reprocess_picture!)
+ images.map do |image|
+ Thread.new do
+ ActiveRecord::Base.connection_pool.with_connection do
+ image.reprocess_picture!
+ end
+ end
+ end.each(&:join)
end
end
View
12 app/models/section.rb
@@ -8,14 +8,24 @@ class Section < ActiveRecord::Base
validates_url_title_unique
+ before_create :set_bottom_position
+
def self.welcome_section
- first
+ joins(:pages).where('pages.id IS NOT NULL').first
end
def welcome_page
pages.first
end
+ def title_visible?
+ !title.start_with?('-')
+ end
+
+ def can_be_deleted?
+ pages.empty?
+ end
+
protected
def order_scope
View
31 app/views/layouts/_sidebar.html.haml
@@ -1,14 +1,21 @@
-%ul.sidebar
+%ul.sidebar{ data: current_user && { sort_update_url: reorder_sections_path } }
- for section in sidebar_sections
- %li.section
- = section.title
- %ul
+ %li.section{ data: { id: section.id } }
+ - if section.title_visible?
+ - if current_user
+ = link_to section.title, section, class: 'section-title', title: 'change title', remote: true, method: :patch, data: { prompt: { message: 'Enter a new title:', default: section.title, param: 'section[title]' } }
+ - else
+ %span.section-title= section.title
+ - elsif current_user
+ .empty-section-title
+ = link_to section.title, section, class: 'section-title', title: 'change title', remote: true, method: :patch, data: { prompt: { message: 'Enter a new title:', default: section.title, param: 'section[title]' } }
+ - if current_user
+ = render 'layouts/sidebar_add_page', section: section
+ - if section.can_be_deleted?
+ = link_to raw('&times;'), section, class: 'admin', title: 'delete section', remote: true, method: :delete, data: { confirm: "Do you really want to delete “#{section.title}”?" }
+ %ul{ data: current_user && { sort_update_url: reorder_section_pages_path(section) } }
- for page in section.pages
- - if page == @page
- %li.page
- - if current_user
- = link_to page.title, [section, page], method: :patch, remote: true, data: { prompt: { message: 'Enter a new zoom factor:', default: page.images_zoom_factor, param: 'page[images_zoom_factor]' } }
- - else
- = page.title
- - else
- %li.page= link_to page.title, page == welcome_page ? root_path : [section, page]
+ = render 'layouts/sidebar_page', section: section, page: page
+ - if current_user
+ %li.admin.add-section
+ = link_to '+', sections_path, class: 'admin add-section', title: 'add section', remote: true, method: :post, data: { prompt: { message: 'Enter a section title:', param: 'section[title]' } }
View
3  app/views/layouts/_sidebar_add_page.html.haml
@@ -0,0 +1,3 @@
+- page = section.dup.pages.build
+
+= link_to '+', [section, page], class: 'admin add-page', title: 'add page', remote: true, method: :post, data: { prompt: { message: 'Enter a page title:', default: page.title, param: 'page[title]' } }
View
13 app/views/layouts/_sidebar_page.html.haml
@@ -0,0 +1,13 @@
+%li.page{ data: { id: page.id } }
+ - if page == @page
+ .current
+ - if current_user
+ = link_to page.title, [section, page], class: 'current', title: 'change title', remote: true, method: :patch, data: { prompt: { message: 'Enter a new title:', default: page.title, param: 'page[title]' } }
+ - if page.images.any?
+ = link_to '%', [section, page], class: 'admin', title: 'change zoom', remote: true, method: :patch, data: { prompt: { message: 'Enter a new zoom factor:', default: page.images_zoom_factor, param: 'page[images_zoom_factor]' } }
+ - if page.can_be_deleted?
+ = link_to raw('&times;'), [section, page], class: 'admin', title: 'delete page', remote: true, method: :delete, data: { confirm: "Do you really want to delete “#{page.title}”?" }
+ - else
+ %span= page.title
+ - else
+ = link_to page.title, page == welcome_page ? root_path : [section, page]
View
1  app/views/pages/create.js.erb
@@ -0,0 +1 @@
+Turbolinks.visit("<%= j url_for([@section, @page]) %>");
View
1  app/views/pages/destroy.js.erb
@@ -0,0 +1 @@
+Turbolinks.visit("<%= j @section.pages.empty? ? root_url : url_for([@section, @section.pages.first]) %>");
View
1  app/views/pages/update.js.erb
@@ -0,0 +1 @@
+Turbolinks.visit("<%= j url_for([@section, @page]) %>");
View
7 config/deploy.rb
@@ -1,9 +1,12 @@
-# config valid only for Capistrano 3.1
-lock '3.2.0'
+# config valid only for Capistrano 3
+lock '3.3.5'
set :application, 'White'
set :repo_url, 'git@github.com:korny/White.git'
+# use the same ruby as used locally for deployment
+# set :rvm1_ruby_version, '2.1.0'
+
# Default branch is :master
set :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
View
10 config/routes.rb
@@ -1,14 +1,14 @@
Rails.application.routes.draw do
resource :session, only: [:create, :destroy]
- resources :sections, only: [], path: '' do
- resources :pages, only: [:show, :update], path: '' do
+ resources :sections, only: [:create, :update, :destroy], path: '' do
+ resources :pages, only: [:show, :create, :update, :destroy], path: '' do
resources :images, only: [:create, :update, :destroy] do
- collection do
- patch :reorder
- end
+ patch :reorder, on: :collection
end
+ patch :reorder, on: :collection
end
+ patch :reorder, on: :collection
end
root 'pages#index'
View
2  lib/assets/javascripts/jquery_ujs.prompt.js.coffee
@@ -4,7 +4,7 @@ $.rails.prompt = (message, defaultValue) ->
$.rails.handlePrompt = (element) ->
config = element.data('prompt')
message = config.message || config
- defaultValue = config.default
+ defaultValue = config.default || ''
param = config.param || 'value'
return true unless message
View
26 lib/tasks/setup.rake
@@ -1,7 +1,7 @@
namespace :white do
- desc 'Set the admin password.'
+ desc 'Create an empty first page and set the admin password.'
task :setup => :environment do
- print 'Admin password: '
+ print "#{User.admin ? 'reset' : 'enter'} admin password: "
password = $stdin.gets.chomp
if password.present?
@@ -9,7 +9,27 @@ namespace :white do
admin.password = password
admin.save!
else
- puts 'Empty password, aborting.'
+ abort 'Empty password, aborting.'
end
+
+ unless Section.welcome_section
+ puts 'Creating first section...'
+ Section.create!(title: 'Home') unless Section.exists?
+
+ puts 'Creating first page...'
+ Section.first.pages.create!(title: 'Example Page', text: <<-MARKDOWN)
+Welcome to your White website!
+
+Start by logging in with your password by moving the cursor to the upper right corner of the page.
+
+You can:
+
+- Add sections and pages in the sidebar
+- Edit text by clicking into the page
+- Add pictures by dragging them into the page
+ MARKDOWN
+ end
+
+ puts 'Done.'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.