From 19a7d51e604de9e3368b1f1b168d3e733113a242 Mon Sep 17 00:00:00 2001
From: ihower
Date: Wed, 13 Apr 2011 18:19:51 +0800
Subject: [PATCH] Chris's first commit at Fri Jan 28 2011 10:14:32 GMT+0800
(CST)
---
.gitignore | 11 +-
Gemfile | 51 +-
Gemfile.lock | 99 +
README | 271 +-
Rakefile | 5 +-
app/controllers/admin/assets_controller.rb | 16 +-
app/controllers/admin/homes_controller.rb | 52 +
app/controllers/admin/items_controller.rb | 35 +-
app/controllers/admin/layouts_controller.rb | 17 +-
app/controllers/admin/links_controller.rb | 16 +-
app/controllers/admin/pages_controller.rb | 17 +-
app/controllers/admin/snippets_controller.rb | 15 +-
.../admin/translations_controller.rb | 78 +
.../admin/user_attribute_models_controller.rb | 48 +
app/controllers/application_controller.rb | 74 +-
app/controllers/pages_controller.rb | 13 +-
app/controllers/panel/users_controller.rb | 14 +-
app/controllers/sites_controller.rb | 18 +
app/helpers/admin_helper.rb | 6 +-
app/helpers/application_helper.rb | 9 +
app/helpers/sites_helper.rb | 2 +
app/models/asset.rb | 41 +-
app/models/attribute_attr_model.rb | 50 +
app/models/home.rb | 10 +
app/models/i18n_liquid.rb | 13 +
app/models/i18n_variable.rb | 9 +
app/models/item.rb | 84 +-
app/models/layout.rb | 15 +-
app/models/link.rb | 8 +-
app/models/page.rb | 14 +-
app/models/site.rb | 8 +
app/models/snippet.rb | 67 +-
app/models/snippet_filter.rb | 22 +-
app/models/user.rb | 56 +-
app/models/user_attribute.rb | 8 +-
app/models/user_attribute_model.rb | 59 +
app/uploaders/asset_uploader.rb | 47 +
app/uploaders/avatar_uploader.rb | 62 +
app/views/admin/assets/_form.html.erb | 8 +-
app/views/admin/assets/edit.html.erb | 8 +-
app/views/admin/assets/index.html.erb | 41 +-
app/views/admin/assets/new.html.erb | 9 +-
app/views/admin/homes/_form.html.erb | 30 +
app/views/admin/homes/edit.html.erb | 10 +
app/views/admin/homes/new.html.erb | 11 +
app/views/admin/items/_component.html.erb | 2 +-
app/views/admin/items/_home.html.erb | 10 +
app/views/admin/items/_link.html.erb | 21 +-
app/views/admin/items/_page.html.erb | 8 +-
app/views/admin/items/_snippets.html.erb | 6 +-
app/views/admin/items/index.html.erb | 62 +-
app/views/admin/layouts/_form.html.erb | 26 +-
app/views/admin/layouts/edit.html.erb | 9 +-
app/views/admin/layouts/index.html.erb | 21 +-
app/views/admin/layouts/new.html.erb | 9 +-
app/views/admin/links/_form.html.erb | 22 +-
app/views/admin/links/edit.html.erb | 8 +-
app/views/admin/links/new.html.erb | 8 +-
app/views/admin/pages/_form.html.erb | 53 +-
app/views/admin/pages/edit.html.erb | 11 +-
app/views/admin/pages/new.html.erb | 8 +-
app/views/admin/snippets/_form.html.erb | 27 +-
app/views/admin/snippets/edit.html.erb | 8 +-
app/views/admin/snippets/new.html.erb | 6 +-
.../admin/translations/_action_bar.html.erb | 1 +
.../translations/_edit_language.html.erb | 16 +
.../_edit_user_attribute_model.html.erb | 34 +
.../admin/translations/_language.html.erb | 16 +
.../_user_attribute_model.html.erb | 34 +
app/views/admin/translations/edit.html.erb | 25 +
app/views/admin/translations/index.html.erb | 69 +
.../_attribute_attr_model.html.erb | 30 +
.../user_attribute_models/_form.html.erb | 73 +
.../admin/user_attribute_models/edit.html.erb | 19 +
.../user_attribute_models/index.html.erb | 26 +
.../admin/user_attribute_models/new.html.erb | 19 +
app/views/devise/menu/_login_items.html.erb | 9 +
.../devise/menu/_registration_items.html.erb | 9 +
app/views/layouts/_lang_menu.html.erb | 7 +
app/views/layouts/admin.html.erb | 27 +-
app/views/layouts/application.html.erb | 47 +
app/views/layouts/panel.html.erb | 18 +-
.../panel/users/_attribute_attr.html.erb | 25 +
app/views/panel/users/_form.html.erb | 57 +-
.../panel/users/_user_attribute.html.erb | 42 +
app/views/panel/users/edit.html.erb | 9 +-
app/views/panel/users/index.html.erb | 23 +-
app/views/panel/users/new.html.erb | 22 +-
app/views/panel/users/show.html.erb | 28 +-
app/views/sites/index.html.erb | 1 +
app/views/sites/new.html.erb | 1 +
config.ru | 2 +-
config/application.rb | 42 +-
config/boot.rb | 24 +-
config/environment.rb | 2 +-
config/environments/development.rb | 10 +-
config/environments/production.rb | 20 +-
config/environments/test.rb | 10 +-
config/initializers/carrierwave.rb | 15 +
config/initializers/devise.rb | 120 +-
config/initializers/inflections.rb | 2 +-
config/initializers/load_lists.rb | 2 +
config/initializers/mongoid.rb | 16 +
config/initializers/secret_token.rb | 7 +
config/initializers/session_store.rb | 13 +-
config/list.yml | 7 +
config/locales/devise.en.yml | 24 +-
config/locales/devise.zh_tw.yml | 39 +
config/locales/en.yml | 100 +-
config/locales/zh_tw.yml | 322 +-
config/mongoid.yml | 23 +
config/routes.rb | 86 +-
lib/grid_io.rb | 22 +
lib/reroute_middleware.rb | 19 +-
lib/snippets/language_bar.snippet | 8 +
lib/tasks/.gitkeep | 0
lib/tasks/dev.rake | 30 +-
public/javascripts/controls.js | 965 +++
public/javascripts/dragdrop.js | 974 +++
public/javascripts/effects.js | 1123 +++
public/javascripts/prototype.js | 6001 +++++++++++++++++
public/javascripts/rails_bak.js | 175 +
public/robots.txt | 4 +-
public/stylesheets/.gitkeep | 0
public/stylesheets/devise.css | 10 +
public/stylesheets/easy.css | 10 +-
script/rails | 8 +-
test/fixtures/sites.yml | 11 +
test/functional/sites_controller_test.rb | 8 +
test/performance/browsing_test.rb | 2 +-
test/test_helper.rb | 8 +-
test/unit/helpers/sites_helper_test.rb | 4 +
test/unit/site_test.rb | 8 +
vendor/plugins/.gitkeep | 0
vendor/plugins/dynamic_form/MIT-LICENSE | 20 +
vendor/plugins/dynamic_form/README | 13 +
vendor/plugins/dynamic_form/Rakefile | 10 +
.../plugins/dynamic_form/dynamic_form.gemspec | 12 +
vendor/plugins/dynamic_form/init.rb | 1 +
.../lib/action_view/helpers/dynamic_form.rb | 300 +
.../lib/action_view/locale/en.yml | 8 +
.../plugins/dynamic_form/lib/dynamic_form.rb | 5 +
.../test/dynamic_form_i18n_test.rb | 42 +
.../dynamic_form/test/dynamic_form_test.rb | 370 +
.../plugins/dynamic_form/test/test_helper.rb | 9 +
145 files changed, 12742 insertions(+), 893 deletions(-)
create mode 100644 Gemfile.lock
create mode 100644 app/controllers/admin/homes_controller.rb
create mode 100644 app/controllers/admin/translations_controller.rb
create mode 100644 app/controllers/admin/user_attribute_models_controller.rb
create mode 100644 app/controllers/sites_controller.rb
create mode 100644 app/helpers/sites_helper.rb
create mode 100644 app/models/attribute_attr_model.rb
create mode 100644 app/models/home.rb
create mode 100644 app/models/i18n_liquid.rb
create mode 100644 app/models/i18n_variable.rb
create mode 100644 app/models/site.rb
create mode 100644 app/models/user_attribute_model.rb
create mode 100644 app/uploaders/asset_uploader.rb
create mode 100644 app/uploaders/avatar_uploader.rb
create mode 100644 app/views/admin/homes/_form.html.erb
create mode 100644 app/views/admin/homes/edit.html.erb
create mode 100644 app/views/admin/homes/new.html.erb
create mode 100644 app/views/admin/items/_home.html.erb
create mode 100644 app/views/admin/translations/_action_bar.html.erb
create mode 100644 app/views/admin/translations/_edit_language.html.erb
create mode 100644 app/views/admin/translations/_edit_user_attribute_model.html.erb
create mode 100644 app/views/admin/translations/_language.html.erb
create mode 100644 app/views/admin/translations/_user_attribute_model.html.erb
create mode 100644 app/views/admin/translations/edit.html.erb
create mode 100644 app/views/admin/translations/index.html.erb
create mode 100644 app/views/admin/user_attribute_models/_attribute_attr_model.html.erb
create mode 100644 app/views/admin/user_attribute_models/_form.html.erb
create mode 100644 app/views/admin/user_attribute_models/edit.html.erb
create mode 100644 app/views/admin/user_attribute_models/index.html.erb
create mode 100644 app/views/admin/user_attribute_models/new.html.erb
create mode 100644 app/views/devise/menu/_login_items.html.erb
create mode 100644 app/views/devise/menu/_registration_items.html.erb
create mode 100644 app/views/layouts/_lang_menu.html.erb
create mode 100644 app/views/layouts/application.html.erb
create mode 100644 app/views/panel/users/_attribute_attr.html.erb
create mode 100644 app/views/panel/users/_user_attribute.html.erb
create mode 100644 app/views/sites/index.html.erb
create mode 100644 app/views/sites/new.html.erb
create mode 100644 config/initializers/carrierwave.rb
create mode 100644 config/initializers/load_lists.rb
create mode 100644 config/initializers/mongoid.rb
create mode 100644 config/initializers/secret_token.rb
create mode 100644 config/list.yml
create mode 100644 config/locales/devise.zh_tw.yml
create mode 100644 config/mongoid.yml
create mode 100644 lib/grid_io.rb
create mode 100644 lib/snippets/language_bar.snippet
create mode 100644 lib/tasks/.gitkeep
create mode 100644 public/javascripts/controls.js
create mode 100644 public/javascripts/dragdrop.js
create mode 100644 public/javascripts/effects.js
create mode 100644 public/javascripts/prototype.js
create mode 100644 public/javascripts/rails_bak.js
create mode 100644 public/stylesheets/.gitkeep
create mode 100644 public/stylesheets/devise.css
create mode 100644 test/fixtures/sites.yml
create mode 100644 test/functional/sites_controller_test.rb
create mode 100644 test/unit/helpers/sites_helper_test.rb
create mode 100644 test/unit/site_test.rb
create mode 100644 vendor/plugins/.gitkeep
create mode 100644 vendor/plugins/dynamic_form/MIT-LICENSE
create mode 100644 vendor/plugins/dynamic_form/README
create mode 100644 vendor/plugins/dynamic_form/Rakefile
create mode 100644 vendor/plugins/dynamic_form/dynamic_form.gemspec
create mode 100644 vendor/plugins/dynamic_form/init.rb
create mode 100644 vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb
create mode 100644 vendor/plugins/dynamic_form/lib/action_view/locale/en.yml
create mode 100644 vendor/plugins/dynamic_form/lib/dynamic_form.rb
create mode 100644 vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb
create mode 100644 vendor/plugins/dynamic_form/test/dynamic_form_test.rb
create mode 100644 vendor/plugins/dynamic_form/test/test_helper.rb
diff --git a/.gitignore b/.gitignore
index 7a9f55cb..3ec457e3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,13 +2,4 @@
db/*.sqlite3
log/*.log
tmp/**/*
-.DS_Store
-config/database.yml
-public/stylesheets/all*
-public/javascripts/all*
-test/unit/*
-test/fixtures/*
-test/functional/*
-coverage/*
-vendor/rails/*
-db/development.sqlite3
\ No newline at end of file
+public/uploads/**/*
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 9abb03d4..3991c75a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,32 +1,37 @@
-# Edit this Gemfile to bundle your application's dependencies.
-source 'http://gemcutter.org'
+source 'http://rubygems.org'
-gem "rails", "3.0.0.beta"
+gem 'rails', '3.0.3'
-gem "liquid"
+gem 'bson_ext'
+gem 'carrierwave'
+gem 'devise'
+gem 'liquid'
+gem 'mini_magick'
+gem 'mongoid', '2.0.0.beta.20'
-# http://github.com/merbjedi/mongomapper
-gem "mongo_mapper-rails3", :require => "mongo_mapper"
-#gem 'grip'
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'warden'
-gem 'devise', "1.1.pre"
-## Bundle edge rails:
-# gem "rails", :git => "git://github.com/rails/rails.git"
+# Use unicorn as the web server
+# gem 'unicorn'
-# ActiveRecord requires a database adapter. By default,
-# Rails has selected sqlite3.
-# gem "sqlite3-ruby", :require => "sqlite3"
+# Deploy with Capistrano
+# gem 'capistrano'
-## Bundle the gems you use:
-# gem "bj"
-# gem "hpricot", "0.6"
-# gem "sqlite3-ruby", :require => "sqlite3"
-# gem "aws-s3", :require => "aws/s3"
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
-## Bundle gems used only in certain environments:
-# gem "rspec", :group => :test
-# group :test do
-# gem "webrat"
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
# end
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 00000000..cea41295
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,99 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.7)
+ bcrypt-ruby (2.1.4)
+ bson (1.1.5)
+ bson_ext (1.1.5)
+ builder (2.1.2)
+ carrierwave (0.5.1)
+ activesupport (~> 3.0)
+ devise (1.1.5)
+ bcrypt-ruby (~> 2.1.2)
+ warden (~> 1.0.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ liquid (2.2.2)
+ mail (2.2.14)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mini_magick (3.2)
+ subexec (~> 0.0.4)
+ mongo (1.1.5)
+ bson (>= 1.1.5)
+ mongoid (2.0.0.beta.20)
+ activemodel (~> 3.0)
+ mongo (~> 1.1)
+ tzinfo (~> 0.3.22)
+ will_paginate (~> 3.0.pre)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ subexec (0.0.4)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+ warden (1.0.3)
+ rack (>= 1.0.0)
+ will_paginate (3.0.pre2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bson_ext
+ carrierwave
+ devise
+ liquid
+ mini_magick
+ mongoid (= 2.0.0.beta.20)
+ rails (= 3.0.3)
diff --git a/README b/README
index 37ec8ea2..fe7013d5 100644
--- a/README
+++ b/README
@@ -1,14 +1,15 @@
== Welcome to Rails
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
-This pattern splits the view (also called the presentation) into "dumb" templates
-that are primarily responsible for inserting pre-built data in between HTML tags.
-The model contains the "smart" domain objects (such as Account, Product, Person,
-Post) that holds all the business logic and knows how to persist themselves to
-a database. The controller handles the incoming requests (such as Save New Account,
-Update Product, Show Post) by manipulating the model and directing data to the view.
+This pattern splits the view (also called the presentation) into "dumb"
+templates that are primarily responsible for inserting pre-built data in between
+HTML tags. The model contains the "smart" domain objects (such as Account,
+Product, Person, Post) that holds all the business logic and knows how to
+persist themselves to a database. The controller handles the incoming requests
+(such as Save New Account, Update Product, Show Post) by manipulating the model
+and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
@@ -21,89 +22,40 @@ layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
+Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
-1. At the command prompt, start a new Rails application using the rails command
- and your application name. Ex: rails myapp
-2. Change directory into myapp and start the web server: script/server (run with --help for options)
-3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
-4. Follow the guidelines to start developing your application
+1. At the command prompt, create a new Rails application:
+ rails new myapp (where myapp is the application name)
+2. Change directory to myapp and start the web server:
+ cd myapp; rails server (run with --help for options)
-== Web Servers
+3. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
-By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
-with a variety of other web servers.
+4. Follow the guidelines to start developing your application. You can find
+the following resources handy:
-Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
-suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as: gem install mongrel.
-More info at: http://mongrel.rubyforge.org
-
-Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
-Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
-FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
-
-== Apache .htaccess example for FCGI/CGI
-
-# General Apache options
-AddHandler fastcgi-script .fcgi
-AddHandler cgi-script .cgi
-Options +FollowSymLinks +ExecCGI
-
-# If you don't want Rails to look in certain directories,
-# use the following rewrite rules so that Apache won't rewrite certain requests
-#
-# Example:
-# RewriteCond %{REQUEST_URI} ^/notrails.*
-# RewriteRule .* - [L]
-
-# Redirect all requests not available on the filesystem to Rails
-# By default the cgi dispatcher is used which is very slow
-#
-# For better performance replace the dispatcher with the fastcgi one
-#
-# Example:
-# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
-RewriteEngine On
-
-# If your Rails application is accessed via an Alias directive,
-# then you MUST also set the RewriteBase in this htaccess file.
-#
-# Example:
-# Alias /myrailsapp /path/to/myrailsapp/public
-# RewriteBase /myrailsapp
-
-RewriteRule ^$ index.html [QSA]
-RewriteRule ^([^.]+)$ $1.html [QSA]
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
-
-# In case Rails experiences terminal errors
-# Instead of displaying this message you can supply a file here which will be rendered instead
-#
-# Example:
-# ErrorDocument 500 /500.html
-
-ErrorDocument 500 "
Application error
Rails application failed to start properly"
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
== Debugging Rails
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
-First area to check is the application log files. Have "tail -f" commands running
-on the server.log and development.log. Rails will automatically display debugging
-and runtime information to these files. Debugging info will also be shown in the
-browser on requests from 127.0.0.1.
+First area to check is the application log files. Have "tail -f" commands
+running on the server.log and development.log. Rails will automatically display
+debugging and runtime information to these files. Debugging info will also be
+shown in the browser on requests from 127.0.0.1.
-You can also log your own messages directly into the log file from your code using
-the Ruby logger class from inside your controllers. Example:
+You can also log your own messages directly into the log file from your code
+using the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base
def destroy
@@ -115,26 +67,27 @@ the Ruby logger class from inside your controllers. Example:
The result will be a message in your log file along the lines of:
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
More information on how to use the logger is at http://www.ruby-doc.org/core/
-Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
+several books available online as well:
-* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-These two online (and free) books will bring you up to speed on the Ruby language
-and also on programming in general.
+These two books will bring you up to speed on the Ruby language and also on
+programming in general.
== Debugger
-Debugger support is available through the debugger command when you start your Mongrel or
-Webrick server with --debugger. This means that you can break out of execution at any point
-in the code, investigate and change the model, AND then resume execution!
-You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
-Example:
+Debugger support is available through the debugger command when you start your
+Mongrel or WEBrick server with --debugger. This means that you can break out of
+execution at any point in the code, investigate and change the model, and then,
+resume execution! You need to install ruby-debug to run the server in debugging
+mode. With gems, use sudo gem install ruby-debug. Example:
class WeblogController < ActionController::Base
def index
@@ -147,97 +100,157 @@ So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
- => "[#nil, \"body\"=>nil, \"id\"=>\"1\"}>,
- #\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+ => "[#nil, "body"=>nil, "id"=>"1"}>,
+ #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
-...and even better is that you can examine how your runtime objects actually work:
+...and even better, you can examine how your runtime objects actually work:
>> f = @posts.first
=> #nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
-Finally, when you're ready to resume execution, you enter "cont"
+Finally, when you're ready to resume execution, you can enter "cont".
== Console
-You can interact with the domain model by starting the console through script/console.
-Here you'll have all parts of the application configured, just like it is when the
-application is running. You can inspect domain models, change values, and save to the
-database. Starting the script without arguments will launch it in the development environment.
-Passing an argument will specify a different environment, like script/console production.
+The console is a Ruby shell, which allows you to interact with your
+application's domain model. Here you'll have all parts of the application
+configured, just like it is when the application is running. You can inspect
+domain models, change values, and save to the database. Starting the script
+without arguments will launch it in the development environment.
+
+To start the console, run rails console from the application
+directory.
+
+Options:
+
+* Passing the -s, --sandbox argument will rollback any modifications
+ made to the database.
+* Passing an environment name as an argument will load the corresponding
+ environment. Example: rails console production.
+
+To reload your controllers and models after launching the console run
+reload!
+
+More information about irb can be found at:
+link:http://www.rubycentral.com/pickaxe/irb.html
-To reload your controllers and models after launching the console run reload!
== dbconsole
-You can go to the command line of your database directly through script/dbconsole.
-You would be connected to the database with the credentials defined in database.yml.
-Starting the script without arguments will connect you to the development database. Passing an
-argument will connect you to a different database, like script/dbconsole production.
-Currently works for mysql, postgresql and sqlite.
+You can go to the command line of your database directly through rails
+dbconsole. You would be connected to the database with the credentials
+defined in database.yml. Starting the script without arguments will connect you
+to the development database. Passing an argument will connect you to a different
+database, like rails dbconsole production. Currently works for MySQL,
+PostgreSQL and SQLite 3.
== Description of Contents
+The default directory structure of a generated Ruby on Rails application:
+
+ |-- app
+ | |-- controllers
+ | |-- helpers
+ | |-- mailers
+ | |-- models
+ | `-- views
+ | `-- layouts
+ |-- config
+ | |-- environments
+ | |-- initializers
+ | `-- locales
+ |-- db
+ |-- doc
+ |-- lib
+ | `-- tasks
+ |-- log
+ |-- public
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
+ |-- script
+ |-- test
+ | |-- fixtures
+ | |-- functional
+ | |-- integration
+ | |-- performance
+ | `-- unit
+ |-- tmp
+ | |-- cache
+ | |-- pids
+ | |-- sessions
+ | `-- sockets
+ `-- vendor
+ `-- plugins
+
app
Holds all the code that's specific to this particular application.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from ApplicationController
- which itself descends from ActionController::Base.
+ automated URL mapping. All controllers should descend from
+ ApplicationController which itself descends from ActionController::Base.
app/models
- Holds models that should be named like post.rb.
- Most models will descend from ActiveRecord::Base.
+ Holds models that should be named like post.rb. Models descend from
+ ActiveRecord::Base by default.
app/views
Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
- syntax.
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
+ eRuby syntax by default.
app/views/layouts
- Holds the template files for layouts to be used with views. This models the common
- header/footer method of wrapping views. In your views, define a layout using the
- layout :default and create a file named default.html.erb. Inside default.html.erb,
- call <% yield %> to render the view using this layout.
+ Holds the template files for layouts to be used with views. This models the
+ common header/footer method of wrapping views. In your views, define a layout
+ using the layout :default and create a file named default.html.erb.
+ Inside default.html.erb, call <% yield %> to render the view using this
+ layout.
app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
- for you automatically when using script/generate for controllers. Helpers can be used to
- wrap functionality for your views into methods.
+ Holds view helpers that should be named like weblogs_helper.rb. These are
+ generated for you automatically when using generators for controllers.
+ Helpers can be used to wrap functionality for your views into methods.
config
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+ Configuration files for the Rails environment, the routing map, the database,
+ and other dependencies.
db
- Contains the database schema in schema.rb. db/migrate contains all
- the sequence of Migrations for your schema.
+ Contains the database schema in schema.rb. db/migrate contains all the
+ sequence of Migrations for your schema.
doc
- This directory is where your application documentation will be stored when generated
- using rake doc:app
+ This directory is where your application documentation will be stored when
+ generated using rake doc:app
lib
- Application specific libraries. Basically, any kind of custom code that doesn't
- belong under controllers, models, or helpers. This directory is in the load path.
+ Application specific libraries. Basically, any kind of custom code that
+ doesn't belong under controllers, models, or helpers. This directory is in
+ the load path.
public
- The directory available for the web server. Contains subdirectories for images, stylesheets,
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
- set as the DOCUMENT_ROOT of your web server.
+ The directory available for the web server. Contains subdirectories for
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
+ server.
script
Helper scripts for automation and generation.
test
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
- test files will be generated for you and placed in this directory.
+ Unit and functional tests along with fixtures. When using the rails generate
+ command, template test files will be generated for you and placed in this
+ directory.
vendor
- External libraries that the application depends on. Also includes the plugins subdirectory.
- If the app has frozen rails, those gems also go here, under vendor/rails/.
- This directory is in the load path.
+ External libraries that the application depends on. Also includes the plugins
+ subdirectory. If the app has frozen rails, those gems also go here, under
+ vendor/rails/. This directory is in the load path.
diff --git a/Rakefile b/Rakefile
index 9cb20464..53b734fe 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,9 +2,6 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
-
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-Rails::Application.load_tasks
+PrototypeR4::Application.load_tasks
diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb
index 74879184..698f6f39 100644
--- a/app/controllers/admin/assets_controller.rb
+++ b/app/controllers/admin/assets_controller.rb
@@ -2,24 +2,24 @@ class Admin::AssetsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
-
- def show
- @asset = Asset.find(params[:id])
- send_data @asset.data.file.read, :filename => @asset.filename,
- :type => @asset.data.content_type,
- :disposition => 'inline' # or 'attachment'
- end
+ before_filter :is_admin?
def index
- @assets = Asset.all
+ @assets = Asset.all.entries
+ end
+
+ def show
+ #TODO
end
def edit
@asset = Asset.find(params[:id])
+ session[:last_page] = get_go_back || admin_assets_url
end
def new
@asset = Asset.new
+ session[:last_page] = get_go_back || admin_assets_url
end
def create
diff --git a/app/controllers/admin/homes_controller.rb b/app/controllers/admin/homes_controller.rb
new file mode 100644
index 00000000..58af4434
--- /dev/null
+++ b/app/controllers/admin/homes_controller.rb
@@ -0,0 +1,52 @@
+class Admin::HomesController < ApplicationController
+
+ layout "admin"
+ before_filter :authenticate_user!
+ before_filter :is_admin?
+
+ def show
+ #TODO
+ end
+
+ def new
+ @home = Home.new
+ @home.is_published = true
+ @home.parent_id = nil
+ session[:last_page] = get_go_back || admin_items_url
+ end
+
+ def edit
+ @home = Home.find(params[:id])
+ @i18n_variable = @home.i18n_variable
+ session[:last_page] = get_go_back || admin_items_url
+ end
+
+ def create
+ @home = Home.new(params[:home])
+
+ if @home.save
+ flash[:notice] = t('admin.create_success_home')
+ redirect_to admin_items_url
+ else
+ render :action => "new"
+ end
+ end
+
+ def update
+ @home = Home.find(params[:id])
+ if @home.update_attributes(params[:home])
+ flash[:notice] = t('admin.update_success_home')
+ redirect_to admin_items_url
+ else
+ render :action => "edit"
+ end
+ end
+
+ def destroy
+ @home = Home.find(params[:id])
+ @home.destroy
+
+ redirect_to admin_items_url
+ end
+
+end
diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb
index 72cb995c..65980b53 100644
--- a/app/controllers/admin/items_controller.rb
+++ b/app/controllers/admin/items_controller.rb
@@ -3,31 +3,34 @@ class Admin::ItemsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
-
before_filter :find_parent_item
before_filter :find_snippets, :only => :index
+ before_filter :is_admin?
def index
- @items = Item.all( :conditions => { :parent_id => @parent_item.id } )
- @items.unshift Item.find_by_name("root") if @parent_item.name == 'root'
- end
-
- def up
- @item = Item.find(params[:id])
- @item.move_higher
- redirect_to admin_items_url( :parent_name => @item.parent_name )
- end
-
- def down
- @item = Item.find(params[:id])
- @item.move_lower
- redirect_to admin_items_url( :parent_name => @item.parent_name )
+ @items = Item.where(:parent_id => @parent_item.id).entries rescue []
+ @items = Item.where(:_type => 'Home').entries unless (!@items.empty? || @parent_item)
end
+
+
+#TODO
+# Allow to move items down and up different parents
+# def up
+# @item = Item.find(params[:id])
+# @item.move_higher
+# redirect_to admin_items_url( :parent_name => @item.parent_name )
+# end
+#
+# def down
+# @item = Item.find(params[:id])
+# @item.move_lower
+# redirect_to admin_items_url( :parent_name => @item.parent_name )
+# end
protected
def find_snippets
- @snippets = Snippet.all( :conditions => { :parent_id => @parent_item.id } )
+ @snippets = Snippet.where( { :parent_id => @parent_item.id } ) rescue nil
end
end
diff --git a/app/controllers/admin/layouts_controller.rb b/app/controllers/admin/layouts_controller.rb
index f9ff6311..1f00ded5 100644
--- a/app/controllers/admin/layouts_controller.rb
+++ b/app/controllers/admin/layouts_controller.rb
@@ -2,33 +2,36 @@ class Admin::LayoutsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
+ before_filter :is_admin?
def index
- @layouts = Layout.all
+ @layouts = Layout.all.entries
end
def show
- @layout = Layout.find(params[:id])
-
- redirect_to "/#{@layout.name}"
+ #TODO
+# @layout = Layout.find(params[:id])
+# redirect_to "/#{@layout.name}"
end
def new
@layout = Layout.new
+ session[:last_page] = get_go_back || admin_layouts_url
end
def edit
@layout = Layout.find(params[:id])
+ session[:last_page] = get_go_back || admin_layouts_url
end
def create
@layout = Layout.new(params[:layout])
if @layout.save
- flash[:notice] = 'Layout was successfully created.'
+ flash[:notice] = t('admin.create_success_layout')
redirect_to admin_layouts_url
else
- render :action => "new"
+ render :action => 'new'
end
end
@@ -36,7 +39,7 @@ class Admin::LayoutsController < ApplicationController
@layout = Layout.find(params[:id])
if @layout.update_attributes(params[:layout])
- flash[:notice] = 'Layout was successfully updated.'
+ flash[:notice] = t('admin.update_success_layout')
redirect_to admin_layouts_url
else
render :action => "edit"
diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb
index b3ae0b78..2c7dc102 100644
--- a/app/controllers/admin/links_controller.rb
+++ b/app/controllers/admin/links_controller.rb
@@ -3,6 +3,7 @@ class Admin::LinksController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :find_parent_item
+ before_filter :is_admin?
def show
#TODO
@@ -11,19 +12,22 @@ class Admin::LinksController < ApplicationController
def new
@link = Link.new
@link.is_published = true
- @link.parent_name = @parent_item.name
+ @link.parent_id = @parent_item.id rescue nil
+ session[:last_page] = get_go_back || admin_links_url
end
def edit
@link = Link.find(params[:id])
+ @i18n_variable = @link.i18n_variable
+ session[:last_page] = get_go_back || admin_links_url
end
def create
@link = Link.new(params[:link])
if @link.save
- flash[:notice] = 'Link was successfully created.'
- redirect_to admin_items_url( :parent_name => @link.parent_name )
+ flash[:notice] = t('admin.create_success_link')
+ redirect_to admin_items_url( :parent_id => @link.parent_id )
else
render :action => "new"
end
@@ -33,8 +37,8 @@ class Admin::LinksController < ApplicationController
@link = Link.find(params[:id])
if @link.update_attributes(params[:link])
- flash[:notice] = 'Link was successfully updated.'
- redirect_to admin_items_url( :parent_name => @link.parent_name )
+ flash[:notice] = t('admin.update_success_link')
+ redirect_to admin_items_url( :parent_id => @link.parent_id )
else
render :action => "edit"
end
@@ -44,7 +48,7 @@ class Admin::LinksController < ApplicationController
@link = Link.find(params[:id])
@link.destroy
- redirect_to admin_items_url( :parent_name => @link.parent_name )
+ redirect_to admin_items_url( :parent_id => @link.parent_id )
end
end
diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb
index 179f775b..ffbdea88 100644
--- a/app/controllers/admin/pages_controller.rb
+++ b/app/controllers/admin/pages_controller.rb
@@ -3,6 +3,7 @@ class Admin::PagesController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :find_parent_item
+ before_filter :is_admin?
def show
#TODO
@@ -11,19 +12,22 @@ class Admin::PagesController < ApplicationController
def new
@page = Page.new
@page.is_published = true
- @page.parent_name = @parent_item.name
+ @page.parent_id = @parent_item.id rescue nil
+ session[:last_page] = get_go_back || admin_items_url
end
def edit
@page = Page.find(params[:id])
+ @i18n_variable = @page.i18n_variable
+ session[:last_page] = get_go_back || admin_items_url
end
def create
@page = Page.new(params[:page])
if @page.save
- flash[:notice] = 'Page was successfully created.'
- redirect_to admin_items_url( :parent_name => @page.parent_name )
+ flash[:notice] = t('admin.create_success_page')
+ redirect_to admin_items_url( :parent_id => @page.parent_id )
else
render :action => "new"
end
@@ -31,10 +35,9 @@ class Admin::PagesController < ApplicationController
def update
@page = Page.find(params[:id])
-
if @page.update_attributes(params[:page])
- flash[:notice] = 'Page was successfully updated.'
- redirect_to admin_items_url( :parent_name => @page.parent_name )
+ flash[:notice] = t('admin.update_success_page')
+ redirect_to admin_items_url( :parent_id => @page.parent_id )
else
render :action => "edit"
end
@@ -44,7 +47,7 @@ class Admin::PagesController < ApplicationController
@page = Page.find(params[:id])
@page.destroy
- redirect_to admin_items_url( :parent_name => @page.parent_name )
+ redirect_to admin_items_url( :parent_id => @page.parent_id )
end
end
diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb
index 57a2f09e..29da1999 100644
--- a/app/controllers/admin/snippets_controller.rb
+++ b/app/controllers/admin/snippets_controller.rb
@@ -3,6 +3,7 @@ class Admin::SnippetsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :find_parent_item
+ before_filter :is_admin?
def show
#TODO
@@ -10,19 +11,21 @@ class Admin::SnippetsController < ApplicationController
def new
@snippet = Snippet.new
- @snippet.parent_name = @parent_item.name
+ @snippet.parent_id = @parent_item.id
+ session[:last_page] = get_go_back || admin_items_url
end
def edit
@snippet = Snippet.find(params[:id])
+ session[:last_page] = get_go_back || admin_items_url
end
def create
@snippet = Snippet.new(params[:snippet])
if @snippet.save
- flash[:notice] = 'Snippet was successfully created.'
- redirect_to admin_items_url( :parent_name => @snippet.parent_name )
+ flash[:notice] = t('admin.create_success_snippet')
+ redirect_to admin_items_url( :parent_id => @snippet.parent_id )
else
render :action => "new"
end
@@ -32,8 +35,8 @@ class Admin::SnippetsController < ApplicationController
@snippet = Snippet.find(params[:id])
if @snippet.update_attributes(params[:snippet])
- flash[:notice] = 'Snippet was successfully updated.'
- redirect_to admin_items_url( :parent_name => @snippet.parent_name )
+ flash[:notice] = t('admin.update_success_snippet')
+ redirect_to admin_items_url( :parent_id => @snippet.parent_id )
else
render :action => "edit"
end
@@ -43,7 +46,7 @@ class Admin::SnippetsController < ApplicationController
@snippet = Snippet.find(params[:id])
@snippet.destroy
- redirect_to admin_items_url( :parent_name => @snippet.parent_name )
+ redirect_to admin_items_url( :parent_id => @snippet.parent_id )
end
end
diff --git a/app/controllers/admin/translations_controller.rb b/app/controllers/admin/translations_controller.rb
new file mode 100644
index 00000000..23a512e5
--- /dev/null
+++ b/app/controllers/admin/translations_controller.rb
@@ -0,0 +1,78 @@
+class Admin::TranslationsController < ApplicationController
+
+ layout "admin"
+ before_filter :authenticate_user!
+ before_filter :is_admin?
+
+ def index
+ set_variables
+ end
+
+ def edit
+ set_variables
+ session[:last_page] = get_go_back || admin_translations_url
+ end
+
+ # Update either the i18n_variables or the languages
+ def update
+ begin
+ case params[:id]
+ # Update the i18n_variables
+ when 'all'
+ params[:i18n_variables].each do |id, var|
+ i18n_variable = I18nVariable.find(id)
+ i18n_variable.update_attributes(var)
+ end
+ # Add a language
+ when 'add'
+ site = Site.find(session[:site])
+ if !site.valid_locales.include?(params[:language])
+ site.valid_locales << params[:language]
+ site.save
+ I18nVariable.create({:key => params[:language], :document_class => 'language'})
+ end
+ # Enable a language
+ when 'enable'
+ site = Site.find(session[:site])
+ if !site.in_use_locales.include?(params[:enable_language])
+ site.in_use_locales << params[:enable_language]
+ site.save
+ end
+ # Disable a language
+ when 'disable'
+ site = Site.find(session[:site])
+ if site.in_use_locales.include?(params[:disable_language])
+ site.in_use_locales.delete(params[:disable_language])
+ site.save
+ end
+ # Delete a language and the corresponding i18n_variables
+ when 'delete'
+ site = Site.find(session[:site])
+ site.in_use_locales.delete(params[:delete_language])
+ site.valid_locales.delete(params[:delete_language])
+ site.save
+ I18nVariable.destroy_all(:conditions => {:document_class => 'language', :key => params[:delete_language]})
+ end
+ redirect_to admin_translations_url
+ rescue
+ set_variables
+ render :action => :edit
+ end
+ end
+
+ protected
+
+ # Get the i18n_variables and languages
+ def set_variables
+ @i18n_variables = I18nVariable.all.entries
+ @language_i18n_variables = @i18n_variables.inject([]) do |result, var|
+ result << var if var.document_class.eql?('language')
+ result
+ end
+ @user_attribute_model_i18n_variables = @i18n_variables.inject([]) do |result, var|
+ result << var if var.document_class.eql?('UserAttributeModel')
+ result
+ end
+ end
+
+end
diff --git a/app/controllers/admin/user_attribute_models_controller.rb b/app/controllers/admin/user_attribute_models_controller.rb
new file mode 100644
index 00000000..18117c44
--- /dev/null
+++ b/app/controllers/admin/user_attribute_models_controller.rb
@@ -0,0 +1,48 @@
+class Admin::UserAttributeModelsController < ApplicationController
+
+ layout "admin"
+ before_filter :authenticate_user!
+ before_filter :is_admin?
+
+ def index
+ @user_attribute_models = UserAttributeModel.all.entries
+ end
+
+ def show
+ @user_attribute_model = UserAttributeModel.find(params[:id])
+ end
+
+ def new
+ @user_attribute_model = UserAttributeModel.new
+ session[:last_page] = get_go_back || admin_user_attribute_models_url
+ end
+
+ def edit
+ @user_attribute_model = UserAttributeModel.find(params[:id])
+ @i18n_variable = @user_attribute_model.i18n_variable
+ session[:last_page] = get_go_back || admin_user_attribute_models_url
+ end
+
+ def create
+ @user_attribute_model = UserAttributeModel.new(params[:user_attribute_model])
+ @user_attribute_model.save
+ redirect_to :action => :index
+ end
+
+ def update
+ @user_attribute_model = UserAttributeModel.find(params[:id])
+ @user_attribute_model.update_attributes(params[:user_attribute_model])
+
+ redirect_to :action => :index
+ end
+
+ def destroy
+ @user_attribute_model = UserAttributeModel.find(params[:id])
+ @user_attribute_model.destroy
+
+ @user_attribute_model.destroy_i18n_variables
+
+ redirect_to :action => :index
+ end
+
+end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0691ae9b..d3246e9a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,10 +2,41 @@ class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
- before_filter :set_locale
+ before_filter :set_locale, :set_site
- Liquid::Template.register_filter(SnippetFilter)
+ # Find the parent for the given item
+ def find_parent_item
+ @parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil
+ end
+
+ # Clean the link back
+ # Remove the locale but keep all the other params
+ def get_go_back
+ begin
+ if env['REQUEST_URI'].include?('locale=')
+ session[:last_page]
+ else
+ target = env['HTTP_REFERER'].split('?')
+ vars = target[1].split('&')
+ vars.delete_if {|var| var.include? 'locale=' }
+ if vars.size > 0
+ target[0].to_s + '?' + vars.join('&')
+ else
+ target[0].to_s
+ end
+ end
+ rescue
+ nil
+ end
+ end
+
+ # Check if the current_user is admin
+ def is_admin?
+ redirect_to root_url unless current_user.admin?
+ end
+
+ # Parse and render the pages with liquid
def render_liquid_page
if @page
@layout = @page.layout
@@ -18,26 +49,31 @@ class ApplicationController < ActionController::Base
end
end
+ # Set I18n.locale
def set_locale
# update session if passed
- if params[:locale] && VALID_LOCALES.include?( params[:locale] )
- session[:locale] = params[:locale]
- end
-
+ session[:locale] = params[:locale] if params[:locale]
+
# set locale based on session or default
- I18n.locale = session[:locale] || I18n.default_locale
- end
-
- def find_parent_item
- @parent_item = Item.find_by_name(params[:parent_name] || 'root')
- unless @parent_item
- @parent_item = Page.create( :name => "root", :title => "root", :layout_name => "root" )
- end
- end
-
- def require_entry_name
- render :text => 'missing entry_name' if params[:entry_name].blank?
- return
+ begin
+ # check if locale is valid for non site pages
+ if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
+ I18n.locale = I18n.default_locale
+ else
+ I18n.locale = session[:locale]
+ end
+ rescue
+ I18n.locale = I18n.default_locale
+ end
end
+ # Set the site variables
+ def set_site
+ # set site if exist or create site
+ site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
+ session[:site] = site.id
+ @site_in_use_locales = site.in_use_locales
+ @site_valid_locales = site.valid_locales
+ end
+
end
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index d4ad8946..8c6b8000 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,7 +1,7 @@
class PagesController < ApplicationController
def index
- @page = Page.find_by_name('root')
+ @page = Home.find_by_name('home')
if @page
render_liquid_page
else
@@ -10,8 +10,15 @@ class PagesController < ApplicationController
end
def show
- @page = Page.find_by_full_name(params[:page_name])
- render_liquid_page
+ item = Item.first(:conditions => {:full_name => params[:page_name]})
+ case item._type
+ when 'Page'
+ @page = item
+ render_liquid_page
+ when 'Link'
+ redirect_to "http://#{item[:url]}"
+ end
+
end
end
diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb
index 4fd14c49..0b481413 100644
--- a/app/controllers/panel/users_controller.rb
+++ b/app/controllers/panel/users_controller.rb
@@ -4,7 +4,7 @@ class Panel::UsersController < ApplicationController
before_filter :authenticate_user!
def index
- @users = User.all
+ @users = User.all.entries
end
def show
@@ -13,7 +13,8 @@ class Panel::UsersController < ApplicationController
def new
@user = User.new
- @user_attributes = UserAttribute.all
+ @user_attribute_models = UserAttributeModel.all.entries
+ session[:last_page] = get_go_back || panel_users_url
end
def create
@@ -27,14 +28,21 @@ class Panel::UsersController < ApplicationController
def edit
@user = User.find(params[:id])
- @user_attributes = UserAttribute.all
+ @user_attribute_models = UserAttributeModel.all.entries
+ session[:last_page] = get_go_back || panel_users_url
end
def update
@user = User.find(params[:id])
+
+ # Update changes to the avatar
+ @user.remove_avatar! if params[:file]
+ @user.avatar = params[:file] if params[:file]
+
if @user.update_attributes(params[:user])
redirect_to :action => :index
else
+ @user_attribute_models = UserAttributeModel.all.entries
render :action => :edit
end
end
diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb
new file mode 100644
index 00000000..cb820fbb
--- /dev/null
+++ b/app/controllers/sites_controller.rb
@@ -0,0 +1,18 @@
+class SitesController < ApplicationController
+
+ #layout 'set_up'
+
+ def index
+ @site = Site.first
+ if @site
+ @title = "site"
+ else
+ redirect_to :action => :new
+ end
+ end
+
+ def new
+ @site = Site.new
+ end
+
+end
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
index 9d85d13e..6ae3a213 100644
--- a/app/helpers/admin_helper.rb
+++ b/app/helpers/admin_helper.rb
@@ -1,8 +1,8 @@
module AdminHelper
- def show_parent_items_link(parent_item)
- @parent_items = @parent_item.ancestors.map{ |i| i.name }
- ( @parent_items.map{ |i| link_to(i, admin_items_path(:parent_name=>i) ) } << parent_item.name ).join("/").html_safe
+ def show_parent_items_link
+ @parent_items = @parent_item.ancestors.map{ |i| i }
+ link_to('/' , admin_items_path) + ( @parent_items.map{ |i| link_to(i.name, admin_items_path(:parent_id=>i.id) ) } << @parent_item.name ).join("/").html_safe
end
end
\ No newline at end of file
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be794..cfda53e6 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,11 @@
module ApplicationHelper
+
+ def colorize_in_use_locale(locale)
+ @site_in_use_locales.include?(locale)? 'green' : 'red'
+ end
+
+ def link_back
+ link_to t('back'), session[:last_page]
+ end
+
end
diff --git a/app/helpers/sites_helper.rb b/app/helpers/sites_helper.rb
new file mode 100644
index 00000000..621069db
--- /dev/null
+++ b/app/helpers/sites_helper.rb
@@ -0,0 +1,2 @@
+module SitesHelper
+end
diff --git a/app/models/asset.rb b/app/models/asset.rb
index ca2608fe..2a4165e5 100644
--- a/app/models/asset.rb
+++ b/app/models/asset.rb
@@ -1,41 +1,12 @@
class Asset
- include MongoMapper::Document
- include Grip::HasAttachment
+ include Mongoid::Document
- key :filename, String, :required => true
- key :description, String
+ mount_uploader :data, AssetUploader
- has_grid_attachment :data, :required => true
+ field :filename
+ field :description
- before_validation :setup_filename
- after_save :save_static_file
- after_destroy :delete_static_file
+ validates_presence_of :filename, :data
- def url
- "/assets/#{self.filename}"
- end
-
- def location
- "#{RAILS_ROOT}/public/assets/#{self.filename}"
- end
-
- protected
-
- def setup_filename
- if self.filename.blank? && self.data
- self.filename = self.data.file_name
- end
- end
-
- def save_static_file
- f = File.new(self.location, "wb")
- f.write(self.data.file.read)
- f.close
- end
-
- def delete_static_file
- File.delete(self.location) rescue nil
- end
-
-end
\ No newline at end of file
+end
diff --git a/app/models/attribute_attr_model.rb b/app/models/attribute_attr_model.rb
new file mode 100644
index 00000000..daeeacfa
--- /dev/null
+++ b/app/models/attribute_attr_model.rb
@@ -0,0 +1,50 @@
+class AttributeAttrModel
+
+ include Mongoid::Document
+
+ field :key
+ field :i18n_variable_id, :type => BSON::ObjectId, :index => true
+ field :markup
+ field :locale, :type => Boolean
+ field :options, :type => Array
+
+ embedded_in :user_attribute_model, :inverse_of => :attribute_attr_models
+ validates_uniqueness_of :key
+
+ # Destroy the i18n_variable
+ def destroy_i18n_variable
+ self.i18n_variable.destroy rescue nil
+ end
+
+ # Get the i18n_variable
+ def i18n_variable
+ @i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
+ end
+
+ # Update or create the i18n_variable record
+ def i18n_variable=(attr)
+ if self.i18n_variable_id
+ self.i18n_variable.update_attributes(attr)
+ else
+ var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_attribute_model.i18n_variable_id}))
+ var.save
+ self.i18n_variable_id = var.id
+ end
+ end
+
+ # Convert the string options into an array
+ def select_options=(var)
+ self.options = var.gsub(' ', '').split(',')
+ end
+
+ # Convert the array options into a string
+ def select_options
+ self.options.to_a.join(', ')
+ end
+
+ # Check if the attribute_attr is set to be destroyed
+ def should_destroy?
+ should_destroy.to_i == 1 rescue nil
+ end
+
+end
diff --git a/app/models/home.rb b/app/models/home.rb
new file mode 100644
index 00000000..4f09596d
--- /dev/null
+++ b/app/models/home.rb
@@ -0,0 +1,10 @@
+class Home < Page
+
+ private
+
+ # Remove the validation for parent_id
+ def validates_presence_of_parent_id?
+ false
+ end
+
+end
diff --git a/app/models/i18n_liquid.rb b/app/models/i18n_liquid.rb
new file mode 100644
index 00000000..10a91178
--- /dev/null
+++ b/app/models/i18n_liquid.rb
@@ -0,0 +1,13 @@
+class I18nLiquid < Liquid::Tag
+
+ def initialize(tag_name, value, tokens)
+ super
+ @value = value.to_s
+ end
+
+ def render(context)
+ I18nVariable.first(:conditions => {:key => @value})[I18n.locale] rescue ''
+ end
+end
+
+Liquid::Template.register_tag('t', I18nLiquid)
diff --git a/app/models/i18n_variable.rb b/app/models/i18n_variable.rb
new file mode 100644
index 00000000..175218b3
--- /dev/null
+++ b/app/models/i18n_variable.rb
@@ -0,0 +1,9 @@
+class I18nVariable
+
+ include Mongoid::Document
+
+ field :key
+ field :document_class
+ field :parent_id, :index => true
+
+end
diff --git a/app/models/item.rb b/app/models/item.rb
index d9091c31..9593a344 100644
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -1,66 +1,86 @@
class Item
- include MongoMapper::Document
+ include Mongoid::Document
- key :_type, String
-
- key :name, String, :required => true, :index => true
- key :full_name, String, :required => true, :index => true
-
- key :parent_id, ObjectId, :index => true
-
- key_i18n :title, String, :required => true
-
- key :position, Integer, :required => true
- key :is_published, Boolean, :required => true, :default => true, :index => true
+ field :name, :index => true
+ field :full_name, :index => true
+ field :i18n_variable_id, :type => BSON::ObjectId
+ field :parent_id, :index => true
+ field :parent_name
+ field :position, :type => Integer
+ field :is_published, :type => Boolean, :default => true, :index => true
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
+ validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
validates_uniqueness_of :name, :scope => :parent_id
+ validates_presence_of :name, :full_name, :position, :is_published
+ validates_presence_of :parent_id, :if => :validates_presence_of_parent_id?
- belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
- many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy
+ referenced_in :parent, :class_name => "Item"
+ references_many :children, :class_name => "Item"
before_validation :setup_default_value
- attr_accessor :parent_name
- def parent_name
- @parent_name || self.parent.name
- end
-
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
+ # Get an array of ancestors
def ancestors
node, nodes = self, []
- nodes << node = node.parent while !node.parent.blank?
+ nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
-
+
+ # Update or create the i18n_variable record
+ def i18n_variable=(attr)
+ if self.i18n_variable_id
+ self.i18n_variable.update_attributes(attr) rescue nil
+ else
+ var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class}))
+ var.save
+ self.i18n_variable_id = var.id
+ end
+ end
+
+ # Get the i18n_variable
+ def i18n_variable
+ @i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
+ end
+
+ # Check if the page is home
+ def is_home?
+ self.name.eql?('home') && self.parent_id.nil?
+ end
+
+ # Build the url from the array of ancestors
def url
urls = ancestors.map{ |a| a.name } << self.name
- urls.delete("root")
- "/#{urls.join("/")}"
+ urls.join("/")
end
protected
def setup_default_value
+ # Set the position value within the parent scope
if self.position.blank?
- max_page = Page.last(:order => 'position')
- self.position = (max_page)? max_page.position.to_i + 1 : 1
+ max_page = Item.where(:parent_id => self.parent_id).count
+ self.position = (max_page)? max_page + 1 : 1
end
- if self.parent_name.blank?
- self.parent_name = nil
- self.parent_id = nil
- else
- self.parent_id = Item.find_by_name( self.parent_name ).id
- end
+ # Set the parent value
+ self.parent_name = Item.first(:conditions => {:id => self.parent_id} ).name rescue nil
+ # Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
+ # Remove root node if not root
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
+
+ # Enable the validation for parent_id
+ def validates_presence_of_parent_id?
+ true
+ end
-end
\ No newline at end of file
+end
diff --git a/app/models/layout.rb b/app/models/layout.rb
index 71d82c2f..1af933f6 100644
--- a/app/models/layout.rb
+++ b/app/models/layout.rb
@@ -1,14 +1,19 @@
class Layout
- include MongoMapper::Document
+ include Mongoid::Document
- key :name, String, :required => true, :index => true
- key :description, String
- key_i18n :content, String
+ field :name, :index => true
+ field :description
+ field :content
- many :children, :class_name => "Item", :foreign_key => "layout_id", :dependent => :nullify
+ references_many :children, :class_name => "Item"
+ validates_presence_of :name
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates_uniqueness_of :name
+ def self.exist_one?
+ Layout.count > 0
+ end
+
end
\ No newline at end of file
diff --git a/app/models/link.rb b/app/models/link.rb
index a7fd9676..4301ead4 100644
--- a/app/models/link.rb
+++ b/app/models/link.rb
@@ -1,9 +1,11 @@
class Link < Item
- key :url, String, :required => true
+ field :url
+ validates_presence_of :url
+
def link
- ApplicationController.helpers.link_to(self.title, self.url)
+ ApplicationController.helpers.link_to(self.name, self.url)
end
-end
\ No newline at end of file
+end
diff --git a/app/models/page.rb b/app/models/page.rb
index 6ccb4244..b9050770 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,12 +1,14 @@
class Page < Item
- include LayoutSupport
+ #include LayoutSupport
- key_i18n :content, String
- key :layout_name, String, :required => true
- key :layout_id, ObjectId, :required => true
+ field :content
+ field :layout_name
+ field :layout_id
- belongs_to :layout
+ validates_presence_of :layout_name, :layout_id
+
+ referenced_in :layout
protected
@@ -14,7 +16,7 @@ class Page < Item
super
if self.layout_name
- self.layout_id = Layout.find_by_name( self.layout_name ).id
+ self.layout_id = Layout.first(:conditions => {:name => self.layout_name} ).id
end
end
diff --git a/app/models/site.rb b/app/models/site.rb
new file mode 100644
index 00000000..de3b954b
--- /dev/null
+++ b/app/models/site.rb
@@ -0,0 +1,8 @@
+class Site
+
+ include Mongoid::Document
+
+ field :in_use_locales, :type => Array
+ field :valid_locales, :type => Array
+
+end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 37a2dfa9..ec0bc5ae 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -1,38 +1,37 @@
class Snippet
- include MongoMapper::Document
+ include Mongoid::Document
- key :name, String, :required => true, :index => true
- key :full_name, String, :required => true, :index => true
-
- key :parent_id, ObjectId, :required => true, :index => true
-
- key_i18n :content, String
-
- before_validation :setup_default_value
- validates_uniqueness_of :name, :scope => :parent_id
-
- belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
-
- attr_accessor :parent_name
- def parent_name
- @parent_name || self.parent.name
- end
-
- protected
+ field :name, :index => true
+ field :full_name, :index => true
+
+ field :parent_id, :index => true
+ field :parent_name
+
+ field :content
+
+ before_validation :setup_default_value
+ validates_presence_of :name, :full_name, :parent_id
+ validates_uniqueness_of :name, :scope => :parent_id
+
+ referenced_in :parent, :class_name => "Item", :foreign_key => :parent_id
- def ancestors
- node, nodes = self, []
- nodes << node = node.parent while !node.parent.blank?
- nodes.reverse
- end
-
- def setup_default_value
- self.parent_id = Item.find_by_name( self.parent_name || 'root' ).id
-
- full_node = self.ancestors.map{ |a| a.name }.push( self.name )
- full_node.shift if full_node.size >= 2
- self.full_name = full_node.join("/")
- end
-
-end
\ No newline at end of file
+ # Get an array of ancestors
+ def ancestors
+ node, nodes = self, []
+ nodes << node = node.parent while !node.parent.blank? rescue nil
+ nodes.reverse
+ end
+
+ def setup_default_value
+ # Set the parent value
+ self.parent_name = Item.find( self.parent_id ).name rescue nil
+
+ # Build the full_name from the ancestors array
+ full_node = self.ancestors.map{ |a| a.name }.push( self.name )
+ # Remove root node if not root
+ full_node.shift if full_node.size >= 2
+ self.full_name = full_node.join("/")
+ end
+
+end
diff --git a/app/models/snippet_filter.rb b/app/models/snippet_filter.rb
index a7414bc1..e085e7c4 100644
--- a/app/models/snippet_filter.rb
+++ b/app/models/snippet_filter.rb
@@ -1,13 +1,27 @@
module SnippetFilter
+
def render_snippet(snippet_name)
- snippet = Snippet.find_by_name(snippet_name)
+ snippet = Snippet.first(:conditions => {:name => snippet_name})
if snippet
return Liquid::Template.parse( snippet.content ).render
else
- return "nothing"
+ return t('nothing')
end
-
+
end
-end
\ No newline at end of file
+
+ def ruling_snippet(snippet_name)
+ case snippet_name
+ when 'language_bar'
+ site = Site.first
+ @site_in_use_locales = site.in_use_locales
+ @site_valid_locales = site.valid_locales
+ end
+ return Liquid::Template.parse( eval(File.open("#{RAILS_ROOT}/lib/snippets/#{snippet_name}.snippet").read) ).render
+ end
+
+end
+
+Liquid::Template.register_filter(SnippetFilter)
diff --git a/app/models/user.rb b/app/models/user.rb
index 612d4705..b792361d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,18 +1,54 @@
class User
- include MongoMapper::Document
+
+ include Mongoid::Document
- devise :authenticatable, :recoverable, :rememberable, :trackable
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
- key :use_attributes, Array
+ mount_uploader :avatar, AvatarUploader
- def method_missing(method)
- safe_read(method)
+ field :admin, :type => Boolean, :default => false
+ field :active_attributes, :type => Array
+
+ embeds_many :user_attributes
+ before_update :clean_active_attributes
+
+ # Update or create the user_attribute records
+ def user_attributes=(attrs)
+ attrs.each do |attributes|
+ if attributes[:id].blank?
+ user_attributes.build(attributes)
+ else
+ user_attribute = user_attributes.detect {|a| a.id.to_s == attributes[:id].to_s }
+ user_attribute.update_attributes(attributes)
+ end
+ end
end
- def safe_read(key)
- self[key]
- rescue MongoMapper::KeyNotFound
- return ""
+ # Get an user_attribute from model key
+ def get_attribute_from_model_key(key)
+ self.user_attributes.detect {|a| a.key.to_s == key.to_s }
end
-end
\ No newline at end of file
+ # Get the active user_attribute_models
+ def get_active_attribute_models
+ self.active_attributes.map{ |attr| get_attribute_model(attr) }
+ end
+
+ # Get an user_attribute_model from key
+ def get_attribute_model(key)
+ UserAttributeModel.first(:conditions => {:key => key})
+ end
+
+ # Get the active attributes names or default to '-'
+ def get_attributes
+ (self.active_attributes.nil? || self.active_attributes.empty?) ? '-' : self.active_attributes.map{|attr| I18nVariable.first(:conditions => {:key => attr})[I18n.locale] rescue attr}.join(' / ')
+ end
+
+ protected
+
+ # Remove empty values
+ def clean_active_attributes
+ self.active_attributes.delete('') if self.active_attributes
+ end
+
+end
diff --git a/app/models/user_attribute.rb b/app/models/user_attribute.rb
index 481410fc..94c7e251 100644
--- a/app/models/user_attribute.rb
+++ b/app/models/user_attribute.rb
@@ -1,9 +1,9 @@
class UserAttribute
- include MongoMapper::Document
+ include Mongoid::Document
- key :key, String
- key_i18n :name, String
- key :attrs, Array
+ field :key
+
+ embedded_in :user, :inverse_of => :user_attributes
end
\ No newline at end of file
diff --git a/app/models/user_attribute_model.rb b/app/models/user_attribute_model.rb
new file mode 100644
index 00000000..1817046a
--- /dev/null
+++ b/app/models/user_attribute_model.rb
@@ -0,0 +1,59 @@
+class UserAttributeModel
+
+ include Mongoid::Document
+
+ field :key
+ field :i18n_variable_id, :type => BSON::ObjectId, :index => true
+
+ embeds_many :attribute_attr_models
+
+ after_update :destroy_attrs
+
+ # Update or create the attribute_attr_model records
+ def attribute_attr_models=(attrs)
+ attrs.each do |attributes|
+ if attributes[:id].blank?
+ attribute_attr_models.build(attributes)
+ else
+ attribute_attr_model = attribute_attr_models.detect {|a| a.id.to_s == attributes[:id].to_s }
+ attribute_attr_model.update_attributes(attributes)
+ end
+ end
+ end
+
+ # Destroy the i18n_variables
+ def destroy_i18n_variables
+ self.i18n_variable.destroy rescue nil
+ self.attribute_attr_models.each do |attr|
+ attr.destroy_i18n_variable
+ end
+ end
+
+ # Update or create the i18n_variable record
+ def i18n_variable=(attr)
+ if self.i18n_variable_id
+ self.i18n_variable.update_attributes(attr) rescue nil
+ else
+ var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class}))
+ var.save
+ self.i18n_variable_id = var.id
+ end
+ end
+
+ # Get the i18n_variable
+ def i18n_variable
+ @i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
+ end
+
+ protected
+
+ # Destroy the attribute_attr_models if marked to destroy
+ def destroy_attrs
+ attribute_attr_models.each do |a|
+ if a.should_destroy?
+ a.destroy
+ end
+ end
+ end
+
+end
diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb
new file mode 100644
index 00000000..32b14a93
--- /dev/null
+++ b/app/uploaders/asset_uploader.rb
@@ -0,0 +1,47 @@
+# encoding: utf-8
+
+class AssetUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or ImageScience support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::ImageScience
+
+ # Choose what kind of storage to use for this uploader:
+ # storage :file
+ # storage :s3
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "assets/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :scale => [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb
new file mode 100644
index 00000000..2d55e675
--- /dev/null
+++ b/app/uploaders/avatar_uploader.rb
@@ -0,0 +1,62 @@
+# encoding: utf-8
+
+class AvatarUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or ImageScience support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::ImageScience
+ include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ # storage :file
+ # storage :s3
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "avatar/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :scale => [50, 50]
+ # end
+
+ version :thumb do
+ process :resize_to_fit => [80, 80]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+# def manipulate!
+# raise current_path.inspect
+# image = ::MiniMagick::Image.open(current_path)
+# image = yield(image)
+# image.write(current_path)
+# ::MiniMagick::Image.open(current_path)
+# rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
+# raise CarrierWave::ProcessingError.new("Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: #{e}")
+# end
+
+end
diff --git a/app/views/admin/assets/_form.html.erb b/app/views/admin/assets/_form.html.erb
index 73f9a316..3ee7c644 100644
--- a/app/views/admin/assets/_form.html.erb
+++ b/app/views/admin/assets/_form.html.erb
@@ -1,16 +1,14 @@
-<%= f.error_messages %>
-
\ No newline at end of file
diff --git a/app/views/admin/assets/edit.html.erb b/app/views/admin/assets/edit.html.erb
index b0a5892c..45b7f978 100644
--- a/app/views/admin/assets/edit.html.erb
+++ b/app/views/admin/assets/edit.html.erb
@@ -1,12 +1,10 @@
-
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/admin/homes/_form.html.erb b/app/views/admin/homes/_form.html.erb
new file mode 100644
index 00000000..c766bb1e
--- /dev/null
+++ b/app/views/admin/homes/_form.html.erb
@@ -0,0 +1,30 @@
+<%= f.hidden_field :parent_id %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/items/_home.html.erb b/app/views/admin/items/_home.html.erb
new file mode 100644
index 00000000..670fc0c0
--- /dev/null
+++ b/app/views/admin/items/_home.html.erb
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/app/views/admin/items/index.html.erb b/app/views/admin/items/index.html.erb
index 5e6d3858..5f0f56ed 100644
--- a/app/views/admin/items/index.html.erb
+++ b/app/views/admin/items/index.html.erb
@@ -1,32 +1,44 @@
<% content_for :secondary do %>
-
-
-<% content_for :page_specific_javascript do %>
-
-<% end -%>
\ No newline at end of file
diff --git a/app/views/admin/layouts/edit.html.erb b/app/views/admin/layouts/edit.html.erb
index ce171a36..6785d1c5 100644
--- a/app/views/admin/layouts/edit.html.erb
+++ b/app/views/admin/layouts/edit.html.erb
@@ -1,12 +1,9 @@
-
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/admin/links/new.html.erb b/app/views/admin/links/new.html.erb
index 780d75e1..0151abc0 100644
--- a/app/views/admin/links/new.html.erb
+++ b/app/views/admin/links/new.html.erb
@@ -1,11 +1,11 @@
-
-
-<% content_for :page_specific_javascript do %>
-
-<% end -%>
\ No newline at end of file
diff --git a/app/views/admin/pages/edit.html.erb b/app/views/admin/pages/edit.html.erb
index 91a5eef9..86f9d617 100644
--- a/app/views/admin/pages/edit.html.erb
+++ b/app/views/admin/pages/edit.html.erb
@@ -1,10 +1,11 @@
-
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/admin/pages/new.html.erb b/app/views/admin/pages/new.html.erb
index aafa8156..5ba7cae0 100644
--- a/app/views/admin/pages/new.html.erb
+++ b/app/views/admin/pages/new.html.erb
@@ -1,11 +1,11 @@
-
-
-<% content_for :page_specific_javascript do %>
-
-<% end -%>
\ No newline at end of file
diff --git a/app/views/admin/snippets/edit.html.erb b/app/views/admin/snippets/edit.html.erb
index a81248e4..b7ae0b93 100644
--- a/app/views/admin/snippets/edit.html.erb
+++ b/app/views/admin/snippets/edit.html.erb
@@ -1,11 +1,11 @@
-
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/admin/snippets/new.html.erb b/app/views/admin/snippets/new.html.erb
index c867d6f7..a2fd23ce 100644
--- a/app/views/admin/snippets/new.html.erb
+++ b/app/views/admin/snippets/new.html.erb
@@ -1,4 +1,4 @@
-
\ No newline at end of file
diff --git a/app/views/admin/user_attribute_models/new.html.erb b/app/views/admin/user_attribute_models/new.html.erb
new file mode 100644
index 00000000..934192d6
--- /dev/null
+++ b/app/views/admin/user_attribute_models/new.html.erb
@@ -0,0 +1,19 @@
+
<%= t('admin.new_user_attribute') %>
+
+
diff --git a/app/views/devise/menu/_login_items.html.erb b/app/views/devise/menu/_login_items.html.erb
new file mode 100644
index 00000000..68ded0dd
--- /dev/null
+++ b/app/views/devise/menu/_login_items.html.erb
@@ -0,0 +1,9 @@
+<% if user_signed_in? %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/devise/menu/_registration_items.html.erb b/app/views/devise/menu/_registration_items.html.erb
new file mode 100644
index 00000000..b3c1bc2c
--- /dev/null
+++ b/app/views/devise/menu/_registration_items.html.erb
@@ -0,0 +1,9 @@
+<% if user_signed_in? %>
+