Chris's first commit at Fri Jan 28 2011 10:14:32 GMT+0800 (CST)

This commit is contained in:
ihower 2011-04-13 18:19:51 +08:00
parent 554aa0a95d
commit 19a7d51e60
145 changed files with 12742 additions and 893 deletions

11
.gitignore vendored
View File

@ -2,13 +2,4 @@
db/*.sqlite3 db/*.sqlite3
log/*.log log/*.log
tmp/**/* tmp/**/*
.DS_Store public/uploads/**/*
config/database.yml
public/stylesheets/all*
public/javascripts/all*
test/unit/*
test/fixtures/*
test/functional/*
coverage/*
vendor/rails/*
db/development.sqlite3

51
Gemfile
View File

@ -1,32 +1,37 @@
# Edit this Gemfile to bundle your application's dependencies. source 'http://rubygems.org'
source 'http://gemcutter.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 # Bundle edge Rails instead:
gem "mongo_mapper-rails3", :require => "mongo_mapper" # gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'grip'
gem 'warden'
gem 'devise', "1.1.pre"
## Bundle edge rails: # Use unicorn as the web server
# gem "rails", :git => "git://github.com/rails/rails.git" # gem 'unicorn'
# ActiveRecord requires a database adapter. By default, # Deploy with Capistrano
# Rails has selected sqlite3. # gem 'capistrano'
# gem "sqlite3-ruby", :require => "sqlite3"
## Bundle the gems you use: # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem "bj" # gem 'ruby-debug'
# gem "hpricot", "0.6" # gem 'ruby-debug19'
# gem "sqlite3-ruby", :require => "sqlite3"
# gem "aws-s3", :require => "aws/s3"
## Bundle gems used only in certain environments: # Bundle the extra gems:
# gem "rspec", :group => :test # gem 'bj'
# group :test do # gem 'nokogiri'
# gem "webrat" # 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 # end

99
Gemfile.lock Normal file
View File

@ -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)

271
README
View File

@ -1,14 +1,15 @@
== Welcome to Rails == Welcome to Rails
Rails is a web-application framework that includes everything needed to create Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern. database-backed web applications according to the Model-View-Control pattern.
This pattern splits the view (also called the presentation) into "dumb" templates This pattern splits the view (also called the presentation) into "dumb"
that are primarily responsible for inserting pre-built data in between HTML tags. templates that are primarily responsible for inserting pre-built data in between
The model contains the "smart" domain objects (such as Account, Product, Person, HTML tags. The model contains the "smart" domain objects (such as Account,
Post) that holds all the business logic and knows how to persist themselves to Product, Person, Post) that holds all the business logic and knows how to
a database. The controller handles the incoming requests (such as Save New Account, persist themselves to a database. The controller handles the incoming requests
Update Product, Show Post) by manipulating the model and directing data to the view. (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 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 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 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 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 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. link:files/vendor/rails/actionpack/README.html.
== Getting Started == Getting Started
1. At the command prompt, start a new Rails application using the <tt>rails</tt> command 1. At the command prompt, create a new Rails application:
and your application name. Ex: rails myapp <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
2. Change directory into myapp and start the web server: <tt>script/server</tt> (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
2. Change directory to <tt>myapp</tt> and start the web server:
<tt>cd myapp; rails server</tt> (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 4. Follow the guidelines to start developing your application. You can find
with a variety of other web servers. the following resources handy:
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
suitable for development and deployment of Rails applications. If you have Ruby Gems installed, * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
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 "<h2>Application error</h2>Rails application failed to start properly"
== Debugging Rails == 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. 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 First area to check is the application log files. Have "tail -f" commands
on the server.log and development.log. Rails will automatically display debugging running on the server.log and development.log. Rails will automatically display
and runtime information to these files. Debugging info will also be shown in the debugging and runtime information to these files. Debugging info will also be
browser on requests from 127.0.0.1. 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 You can also log your own messages directly into the log file from your code
the Ruby logger class from inside your controllers. Example: using the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base class WeblogController < ActionController::Base
def destroy 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: 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/ 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/ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) * 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 These two books will bring you up to speed on the Ruby language and also on
and also on programming in general. programming in general.
== Debugger == Debugger
Debugger support is available through the debugger command when you start your Mongrel or Debugger support is available through the debugger command when you start your
Webrick server with --debugger. This means that you can break out of execution at any point Mongrel or WEBrick server with --debugger. This means that you can break out of
in the code, investigate and change the model, AND then resume execution! execution at any point in the code, investigate and change the model, and then,
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug' resume execution! You need to install ruby-debug to run the server in debugging
Example: mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
class WeblogController < ActionController::Base class WeblogController < ActionController::Base
def index 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: with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect >> @posts.inspect
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>, => "[#<Post:0x14a6be8
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]" @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
#<Post:0x14a6620
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger" >> @posts.first.title = "hello from a debugger"
=> "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 >> f = @posts.first
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}> => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
>> f. >> f.
Display all 152 possibilities? (y or n) 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 == Console
You can interact with the domain model by starting the console through <tt>script/console</tt>. The console is a Ruby shell, which allows you to interact with your
Here you'll have all parts of the application configured, just like it is when the application's domain model. Here you'll have all parts of the application
application is running. You can inspect domain models, change values, and save to the configured, just like it is when the application is running. You can inspect
database. Starting the script without arguments will launch it in the development environment. domain models, change values, and save to the database. Starting the script
Passing an argument will specify a different environment, like <tt>script/console production</tt>. without arguments will launch it in the development environment.
To start the console, run <tt>rails console</tt> from the application
directory.
Options:
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
made to the database.
* Passing an environment name as an argument will load the corresponding
environment. Example: <tt>rails console production</tt>.
To reload your controllers and models after launching the console run
<tt>reload!</tt>
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 <tt>reload!</tt>
== dbconsole == dbconsole
You can go to the command line of your database directly through <tt>script/dbconsole</tt>. You can go to the command line of your database directly through <tt>rails
You would be connected to the database with the credentials defined in database.yml. dbconsole</tt>. You would be connected to the database with the credentials
Starting the script without arguments will connect you to the development database. Passing an defined in database.yml. Starting the script without arguments will connect you
argument will connect you to a different database, like <tt>script/dbconsole production</tt>. to the development database. Passing an argument will connect you to a different
Currently works for mysql, postgresql and sqlite. database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
PostgreSQL and SQLite 3.
== Description of Contents == 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 app
Holds all the code that's specific to this particular application. Holds all the code that's specific to this particular application.
app/controllers app/controllers
Holds controllers that should be named like weblogs_controller.rb for Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from ApplicationController automated URL mapping. All controllers should descend from
which itself descends from ActionController::Base. ApplicationController which itself descends from ActionController::Base.
app/models app/models
Holds models that should be named like post.rb. Holds models that should be named like post.rb. Models descend from
Most models will descend from ActiveRecord::Base. ActiveRecord::Base by default.
app/views app/views
Holds the template files for the view that should be named like 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 weblogs/index.html.erb for the WeblogsController#index action. All views use
syntax. eRuby syntax by default.
app/views/layouts app/views/layouts
Holds the template files for layouts to be used with views. This models the common Holds the template files for layouts to be used with views. This models the
header/footer method of wrapping views. In your views, define a layout using the common header/footer method of wrapping views. In your views, define a layout
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb, using the <tt>layout :default</tt> and create a file named default.html.erb.
call <% yield %> to render the view using this layout. Inside default.html.erb, call <% yield %> to render the view using this
layout.
app/helpers app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are generated Holds view helpers that should be named like weblogs_helper.rb. These are
for you automatically when using script/generate for controllers. Helpers can be used to generated for you automatically when using generators for controllers.
wrap functionality for your views into methods. Helpers can be used to wrap functionality for your views into methods.
config 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 db
Contains the database schema in schema.rb. db/migrate contains all Contains the database schema in schema.rb. db/migrate contains all the
the sequence of Migrations for your schema. sequence of Migrations for your schema.
doc doc
This directory is where your application documentation will be stored when generated This directory is where your application documentation will be stored when
using <tt>rake doc:app</tt> generated using <tt>rake doc:app</tt>
lib lib
Application specific libraries. Basically, any kind of custom code that doesn't Application specific libraries. Basically, any kind of custom code that
belong under controllers, models, or helpers. This directory is in the load path. doesn't belong under controllers, models, or helpers. This directory is in
the load path.
public public
The directory available for the web server. Contains subdirectories for images, stylesheets, The directory available for the web server. Contains subdirectories for
and javascripts. Also contains the dispatchers and the default HTML files. This should be images, stylesheets, and javascripts. Also contains the dispatchers and the
set as the DOCUMENT_ROOT of your web server. default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.
script script
Helper scripts for automation and generation. Helper scripts for automation and generation.
test test
Unit and functional tests along with fixtures. When using the script/generate scripts, template Unit and functional tests along with fixtures. When using the rails generate
test files will be generated for you and placed in this directory. command, template test files will be generated for you and placed in this
directory.
vendor vendor
External libraries that the application depends on. Also includes the plugins subdirectory. External libraries that the application depends on. Also includes the plugins
If the app has frozen rails, those gems also go here, under vendor/rails/. subdirectory. If the app has frozen rails, those gems also go here, under
This directory is in the load path. vendor/rails/. This directory is in the load path.

View File

@ -2,9 +2,6 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__) require File.expand_path('../config/application', __FILE__)
require 'rake' require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
Rails::Application.load_tasks PrototypeR4::Application.load_tasks

View File

@ -2,24 +2,24 @@ class Admin::AssetsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :is_admin?
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
def index def index
@assets = Asset.all @assets = Asset.all.entries
end
def show
#TODO
end end
def edit def edit
@asset = Asset.find(params[:id]) @asset = Asset.find(params[:id])
session[:last_page] = get_go_back || admin_assets_url
end end
def new def new
@asset = Asset.new @asset = Asset.new
session[:last_page] = get_go_back || admin_assets_url
end end
def create def create

View File

@ -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

View File

@ -3,31 +3,34 @@ class Admin::ItemsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :find_parent_item before_filter :find_parent_item
before_filter :find_snippets, :only => :index before_filter :find_snippets, :only => :index
before_filter :is_admin?
def index def index
@items = Item.all( :conditions => { :parent_id => @parent_item.id } ) @items = Item.where(:parent_id => @parent_item.id).entries rescue []
@items.unshift Item.find_by_name("root") if @parent_item.name == 'root' @items = Item.where(:_type => 'Home').entries unless (!@items.empty? || @parent_item)
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 )
end 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 protected
def find_snippets def find_snippets
@snippets = Snippet.all( :conditions => { :parent_id => @parent_item.id } ) @snippets = Snippet.where( { :parent_id => @parent_item.id } ) rescue nil
end end
end end

View File

@ -2,33 +2,36 @@ class Admin::LayoutsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :is_admin?
def index def index
@layouts = Layout.all @layouts = Layout.all.entries
end end
def show def show
@layout = Layout.find(params[:id]) #TODO
# @layout = Layout.find(params[:id])
redirect_to "/#{@layout.name}" # redirect_to "/#{@layout.name}"
end end
def new def new
@layout = Layout.new @layout = Layout.new
session[:last_page] = get_go_back || admin_layouts_url
end end
def edit def edit
@layout = Layout.find(params[:id]) @layout = Layout.find(params[:id])
session[:last_page] = get_go_back || admin_layouts_url
end end
def create def create
@layout = Layout.new(params[:layout]) @layout = Layout.new(params[:layout])
if @layout.save if @layout.save
flash[:notice] = 'Layout was successfully created.' flash[:notice] = t('admin.create_success_layout')
redirect_to admin_layouts_url redirect_to admin_layouts_url
else else
render :action => "new" render :action => 'new'
end end
end end
@ -36,7 +39,7 @@ class Admin::LayoutsController < ApplicationController
@layout = Layout.find(params[:id]) @layout = Layout.find(params[:id])
if @layout.update_attributes(params[:layout]) if @layout.update_attributes(params[:layout])
flash[:notice] = 'Layout was successfully updated.' flash[:notice] = t('admin.update_success_layout')
redirect_to admin_layouts_url redirect_to admin_layouts_url
else else
render :action => "edit" render :action => "edit"

View File

@ -3,6 +3,7 @@ class Admin::LinksController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :find_parent_item before_filter :find_parent_item
before_filter :is_admin?
def show def show
#TODO #TODO
@ -11,19 +12,22 @@ class Admin::LinksController < ApplicationController
def new def new
@link = Link.new @link = Link.new
@link.is_published = true @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 end
def edit def edit
@link = Link.find(params[:id]) @link = Link.find(params[:id])
@i18n_variable = @link.i18n_variable
session[:last_page] = get_go_back || admin_links_url
end end
def create def create
@link = Link.new(params[:link]) @link = Link.new(params[:link])
if @link.save if @link.save
flash[:notice] = 'Link was successfully created.' flash[:notice] = t('admin.create_success_link')
redirect_to admin_items_url( :parent_name => @link.parent_name ) redirect_to admin_items_url( :parent_id => @link.parent_id )
else else
render :action => "new" render :action => "new"
end end
@ -33,8 +37,8 @@ class Admin::LinksController < ApplicationController
@link = Link.find(params[:id]) @link = Link.find(params[:id])
if @link.update_attributes(params[:link]) if @link.update_attributes(params[:link])
flash[:notice] = 'Link was successfully updated.' flash[:notice] = t('admin.update_success_link')
redirect_to admin_items_url( :parent_name => @link.parent_name ) redirect_to admin_items_url( :parent_id => @link.parent_id )
else else
render :action => "edit" render :action => "edit"
end end
@ -44,7 +48,7 @@ class Admin::LinksController < ApplicationController
@link = Link.find(params[:id]) @link = Link.find(params[:id])
@link.destroy @link.destroy
redirect_to admin_items_url( :parent_name => @link.parent_name ) redirect_to admin_items_url( :parent_id => @link.parent_id )
end end
end end

View File

@ -3,6 +3,7 @@ class Admin::PagesController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :find_parent_item before_filter :find_parent_item
before_filter :is_admin?
def show def show
#TODO #TODO
@ -11,19 +12,22 @@ class Admin::PagesController < ApplicationController
def new def new
@page = Page.new @page = Page.new
@page.is_published = true @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 end
def edit def edit
@page = Page.find(params[:id]) @page = Page.find(params[:id])
@i18n_variable = @page.i18n_variable
session[:last_page] = get_go_back || admin_items_url
end end
def create def create
@page = Page.new(params[:page]) @page = Page.new(params[:page])
if @page.save if @page.save
flash[:notice] = 'Page was successfully created.' flash[:notice] = t('admin.create_success_page')
redirect_to admin_items_url( :parent_name => @page.parent_name ) redirect_to admin_items_url( :parent_id => @page.parent_id )
else else
render :action => "new" render :action => "new"
end end
@ -31,10 +35,9 @@ class Admin::PagesController < ApplicationController
def update def update
@page = Page.find(params[:id]) @page = Page.find(params[:id])
if @page.update_attributes(params[:page]) if @page.update_attributes(params[:page])
flash[:notice] = 'Page was successfully updated.' flash[:notice] = t('admin.update_success_page')
redirect_to admin_items_url( :parent_name => @page.parent_name ) redirect_to admin_items_url( :parent_id => @page.parent_id )
else else
render :action => "edit" render :action => "edit"
end end
@ -44,7 +47,7 @@ class Admin::PagesController < ApplicationController
@page = Page.find(params[:id]) @page = Page.find(params[:id])
@page.destroy @page.destroy
redirect_to admin_items_url( :parent_name => @page.parent_name ) redirect_to admin_items_url( :parent_id => @page.parent_id )
end end
end end

View File

@ -3,6 +3,7 @@ class Admin::SnippetsController < ApplicationController
layout "admin" layout "admin"
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :find_parent_item before_filter :find_parent_item
before_filter :is_admin?
def show def show
#TODO #TODO
@ -10,19 +11,21 @@ class Admin::SnippetsController < ApplicationController
def new def new
@snippet = Snippet.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 end
def edit def edit
@snippet = Snippet.find(params[:id]) @snippet = Snippet.find(params[:id])
session[:last_page] = get_go_back || admin_items_url
end end
def create def create
@snippet = Snippet.new(params[:snippet]) @snippet = Snippet.new(params[:snippet])
if @snippet.save if @snippet.save
flash[:notice] = 'Snippet was successfully created.' flash[:notice] = t('admin.create_success_snippet')
redirect_to admin_items_url( :parent_name => @snippet.parent_name ) redirect_to admin_items_url( :parent_id => @snippet.parent_id )
else else
render :action => "new" render :action => "new"
end end
@ -32,8 +35,8 @@ class Admin::SnippetsController < ApplicationController
@snippet = Snippet.find(params[:id]) @snippet = Snippet.find(params[:id])
if @snippet.update_attributes(params[:snippet]) if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.' flash[:notice] = t('admin.update_success_snippet')
redirect_to admin_items_url( :parent_name => @snippet.parent_name ) redirect_to admin_items_url( :parent_id => @snippet.parent_id )
else else
render :action => "edit" render :action => "edit"
end end
@ -43,7 +46,7 @@ class Admin::SnippetsController < ApplicationController
@snippet = Snippet.find(params[:id]) @snippet = Snippet.find(params[:id])
@snippet.destroy @snippet.destroy
redirect_to admin_items_url( :parent_name => @snippet.parent_name ) redirect_to admin_items_url( :parent_id => @snippet.parent_id )
end end
end end

View File

@ -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

View File

@ -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

View File

@ -2,10 +2,41 @@ class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
helper :all 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 def render_liquid_page
if @page if @page
@layout = @page.layout @layout = @page.layout
@ -18,26 +49,31 @@ class ApplicationController < ActionController::Base
end end
end end
# Set I18n.locale
def set_locale def set_locale
# update session if passed # update session if passed
if params[:locale] && VALID_LOCALES.include?( params[:locale] ) session[:locale] = params[:locale] if params[:locale]
session[:locale] = params[:locale]
end
# set locale based on session or default # set locale based on session or default
I18n.locale = session[:locale] || I18n.default_locale begin
end # 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])
def find_parent_item I18n.locale = I18n.default_locale
@parent_item = Item.find_by_name(params[:parent_name] || 'root') else
unless @parent_item I18n.locale = session[:locale]
@parent_item = Page.create( :name => "root", :title => "root", :layout_name => "root" ) end
end rescue
end I18n.locale = I18n.default_locale
end
def require_entry_name
render :text => 'missing entry_name' if params[:entry_name].blank?
return
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 end

View File

@ -1,7 +1,7 @@
class PagesController < ApplicationController class PagesController < ApplicationController
def index def index
@page = Page.find_by_name('root') @page = Home.find_by_name('home')
if @page if @page
render_liquid_page render_liquid_page
else else
@ -10,8 +10,15 @@ class PagesController < ApplicationController
end end
def show def show
@page = Page.find_by_full_name(params[:page_name]) item = Item.first(:conditions => {:full_name => params[:page_name]})
render_liquid_page case item._type
when 'Page'
@page = item
render_liquid_page
when 'Link'
redirect_to "http://#{item[:url]}"
end
end end
end end

View File

@ -4,7 +4,7 @@ class Panel::UsersController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def index def index
@users = User.all @users = User.all.entries
end end
def show def show
@ -13,7 +13,8 @@ class Panel::UsersController < ApplicationController
def new def new
@user = User.new @user = User.new
@user_attributes = UserAttribute.all @user_attribute_models = UserAttributeModel.all.entries
session[:last_page] = get_go_back || panel_users_url
end end
def create def create
@ -27,14 +28,21 @@ class Panel::UsersController < ApplicationController
def edit def edit
@user = User.find(params[:id]) @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 end
def update def update
@user = User.find(params[:id]) @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]) if @user.update_attributes(params[:user])
redirect_to :action => :index redirect_to :action => :index
else else
@user_attribute_models = UserAttributeModel.all.entries
render :action => :edit render :action => :edit
end end
end end

View File

@ -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

View File

@ -1,8 +1,8 @@
module AdminHelper module AdminHelper
def show_parent_items_link(parent_item) def show_parent_items_link
@parent_items = @parent_item.ancestors.map{ |i| i.name } @parent_items = @parent_item.ancestors.map{ |i| i }
( @parent_items.map{ |i| link_to(i, admin_items_path(:parent_name=>i) ) } << parent_item.name ).join("/").html_safe 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
end end

View File

@ -1,2 +1,11 @@
module ApplicationHelper 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 end

View File

@ -0,0 +1,2 @@
module SitesHelper
end

View File

@ -1,41 +1,12 @@
class Asset class Asset
include MongoMapper::Document include Mongoid::Document
include Grip::HasAttachment
key :filename, String, :required => true mount_uploader :data, AssetUploader
key :description, String
has_grid_attachment :data, :required => true field :filename
field :description
before_validation :setup_filename validates_presence_of :filename, :data
after_save :save_static_file
after_destroy :delete_static_file
def url end
"/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

View File

@ -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

10
app/models/home.rb Normal file
View File

@ -0,0 +1,10 @@
class Home < Page
private
# Remove the validation for parent_id
def validates_presence_of_parent_id?
false
end
end

13
app/models/i18n_liquid.rb Normal file
View File

@ -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)

View File

@ -0,0 +1,9 @@
class I18nVariable
include Mongoid::Document
field :key
field :document_class
field :parent_id, :index => true
end

View File

@ -1,66 +1,86 @@
class Item class Item
include MongoMapper::Document include Mongoid::Document
key :_type, String field :name, :index => true
field :full_name, :index => true
key :name, String, :required => true, :index => true field :i18n_variable_id, :type => BSON::ObjectId
key :full_name, String, :required => true, :index => true field :parent_id, :index => true
field :parent_name
key :parent_id, ObjectId, :index => true field :position, :type => Integer
field :is_published, :type => Boolean, :default => true, :index => true
key_i18n :title, String, :required => true
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ 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_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 referenced_in :parent, :class_name => "Item"
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy references_many :children, :class_name => "Item"
before_validation :setup_default_value 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) def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true }) Item.first(:conditions => { :name => item_name, :is_published => true })
end end
# Get an array of ancestors
def ancestors def ancestors
node, nodes = self, [] node, nodes = self, []
nodes << node = node.parent while !node.parent.blank? nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse nodes.reverse
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.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 def url
urls = ancestors.map{ |a| a.name } << self.name urls = ancestors.map{ |a| a.name } << self.name
urls.delete("root") urls.join("/")
"/#{urls.join("/")}"
end end
protected protected
def setup_default_value def setup_default_value
# Set the position value within the parent scope
if self.position.blank? if self.position.blank?
max_page = Page.last(:order => 'position') max_page = Item.where(:parent_id => self.parent_id).count
self.position = (max_page)? max_page.position.to_i + 1 : 1 self.position = (max_page)? max_page + 1 : 1
end end
if self.parent_name.blank? # Set the parent value
self.parent_name = nil self.parent_name = Item.first(:conditions => {:id => self.parent_id} ).name rescue nil
self.parent_id = nil
else
self.parent_id = Item.find_by_name( self.parent_name ).id
end
# Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name ) 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 full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/") self.full_name = full_node.join("/")
end end
# Enable the validation for parent_id
def validates_presence_of_parent_id?
true
end
end end

View File

@ -1,14 +1,19 @@
class Layout class Layout
include MongoMapper::Document include Mongoid::Document
key :name, String, :required => true, :index => true field :name, :index => true
key :description, String field :description
key_i18n :content, String 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_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates_uniqueness_of :name validates_uniqueness_of :name
def self.exist_one?
Layout.count > 0
end
end end

View File

@ -1,9 +1,11 @@
class Link < Item class Link < Item
key :url, String, :required => true field :url
validates_presence_of :url
def link def link
ApplicationController.helpers.link_to(self.title, self.url) ApplicationController.helpers.link_to(self.name, self.url)
end end
end end

View File

@ -1,12 +1,14 @@
class Page < Item class Page < Item
include LayoutSupport #include LayoutSupport
key_i18n :content, String field :content
key :layout_name, String, :required => true field :layout_name
key :layout_id, ObjectId, :required => true field :layout_id
belongs_to :layout validates_presence_of :layout_name, :layout_id
referenced_in :layout
protected protected
@ -14,7 +16,7 @@ class Page < Item
super super
if self.layout_name 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
end end

8
app/models/site.rb Normal file
View File

@ -0,0 +1,8 @@
class Site
include Mongoid::Document
field :in_use_locales, :type => Array
field :valid_locales, :type => Array
end

View File

@ -1,38 +1,37 @@
class Snippet class Snippet
include MongoMapper::Document include Mongoid::Document
key :name, String, :required => true, :index => true field :name, :index => true
key :full_name, String, :required => true, :index => true field :full_name, :index => true
key :parent_id, ObjectId, :required => true, :index => true field :parent_id, :index => true
field :parent_name
key_i18n :content, String
field :content
before_validation :setup_default_value
validates_uniqueness_of :name, :scope => :parent_id before_validation :setup_default_value
validates_presence_of :name, :full_name, :parent_id
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id validates_uniqueness_of :name, :scope => :parent_id
attr_accessor :parent_name referenced_in :parent, :class_name => "Item", :foreign_key => :parent_id
def parent_name
@parent_name || self.parent.name
end
protected
def ancestors # Get an array of ancestors
node, nodes = self, [] def ancestors
nodes << node = node.parent while !node.parent.blank? node, nodes = self, []
nodes.reverse nodes << node = node.parent while !node.parent.blank? rescue nil
end nodes.reverse
end
def setup_default_value
self.parent_id = Item.find_by_name( self.parent_name || 'root' ).id def setup_default_value
# Set the parent value
full_node = self.ancestors.map{ |a| a.name }.push( self.name ) self.parent_name = Item.find( self.parent_id ).name rescue nil
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/") # Build the full_name from the ancestors array
end full_node = self.ancestors.map{ |a| a.name }.push( self.name )
# Remove root node if not root
end full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
end

View File

@ -1,13 +1,27 @@
module SnippetFilter module SnippetFilter
def render_snippet(snippet_name) def render_snippet(snippet_name)
snippet = Snippet.find_by_name(snippet_name) snippet = Snippet.first(:conditions => {:name => snippet_name})
if snippet if snippet
return Liquid::Template.parse( snippet.content ).render return Liquid::Template.parse( snippet.content ).render
else else
return "nothing" return t('nothing')
end end
end end
end
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)

View File

@ -1,18 +1,54 @@
class User 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) field :admin, :type => Boolean, :default => false
safe_read(method) 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 end
def safe_read(key) # Get an user_attribute from model key
self[key] def get_attribute_from_model_key(key)
rescue MongoMapper::KeyNotFound self.user_attributes.detect {|a| a.key.to_s == key.to_s }
return ""
end end
end # 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

View File

@ -1,9 +1,9 @@
class UserAttribute class UserAttribute
include MongoMapper::Document include Mongoid::Document
key :key, String field :key
key_i18n :name, String
key :attrs, Array embedded_in :user, :inverse_of => :user_attributes
end end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,16 +1,14 @@
<%= f.error_messages %>
<p> <p>
<%= f.label :filename, "FileName" %> <%= f.label :filename, t('admin.file_name') %>
<%= f.text_field :filename, :class => 'text' %> <%= f.text_field :filename, :class => 'text' %>
</p> </p>
<p> <p>
<%= f.label :description, "Description" %> <%= f.label :description, t('admin.description') %>
<%= f.text_field :description, :class => 'text' %> <%= f.text_field :description, :class => 'text' %>
</p> </p>
<p> <p>
<%= f.label :data, "Data" %> <%= f.label :data, t('admin.data') %>
<%= f.file_field :data %> <%= f.file_field :data %>
</p> </p>

View File

@ -1,12 +1,10 @@
<h1>Editing assets</h1> <h1><%= t('editing_asset') %></h1>
<% form_for @asset, :url => admin_asset_path(@asset), :html => { :multipart => true } do |f| %> <% form_for @asset, :url => admin_asset_path(@asset), :html => { :multipart => true } do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Update' %> <%= f.submit t('update') %> <%= link_back %>
</p> </p>
<% end %> <% end %>
<%= link_to 'Back', admin_assets_path %>

View File

@ -1,31 +1,32 @@
<h1>Listing assets</h1> <% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_assets') %></h1>
<table> <table>
<tr> <tr>
<th>檔案</th> <th><%= t('admin.file_name') %></th>
<th>描述</th> <th><%= t('admin.description') %></th>
<th>格式</th> <th><%= t('admin.format') %></th>
<th>原上傳檔名</th> <th><%= t('admin.orig_upload_file') %></th>
<th>檔案大小</th> <th><%= t('admin.file_name') %></th>
<th></th> <th><%= t('admin.action') %></th>
<th></th>
</tr> </tr>
<% @assets.each do |asset| %> <% @assets.each do |asset| %>
<tr> <tr>
<td><%#= link_to asset.filename, admin_asset_path(asset) %> <td><%= link_to asset.filename, asset.data.url, :target => '_blank' %></td>
<%= link_to asset.url, asset.url %>
</td>
<td><%= asset.description %></td> <td><%= asset.description %></td>
<td><%= asset.data.content_type %></td> <td><%= asset.data.file.content_type %></td>
<td><%= asset.data.file_name %></td> <td><%= asset.data_filename %></td>
<td><%= number_to_human_size(asset.data.file_size) %></td> <td><%= number_to_human_size(asset.data.file.file_length) %></td>
<td><%= link_to t(:edit), edit_admin_asset_path(asset) %></td> <td>
<td><%= link_to t(:delete), admin_asset_path(asset), :confirm => 'Are you sure?', :method => :delete %></td> <%= link_to t(:edit), edit_admin_asset_path(asset) %> |
<%= link_to t(:delete), admin_asset_path(asset), :confirm => t('sure?'), :method => :delete %>
</td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<br />
<%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %>

View File

@ -1,11 +1,10 @@
<h1>New Asset</h1> <h1><%= t('admin.new_asset') %></h1>
<% form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %> <%= form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Create' %> <%= f.submit t('create') %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -0,0 +1,30 @@
<%= f.hidden_field :parent_id %>
<p>
<%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
<%= f.hidden_field :name, :value => 'home' %>
</p>
<% @site_valid_locales.each do |locale| %>
<p>
<%= label_tag "#{f}[title]", "#{t('admin.title')} #{locale}" %>
<%= text_field_tag "#{f}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p>
<%= f.label :layout_name, t('admin.layout_name') %>
<%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p>
<p>
<%= f.label "content", t('admin.content') %>
<%= f.text_area "content", :size => '100x30' %>
</p>
<p>
<%= f.label :is_published, "#{t('admin.is_published')} ?" %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p>

View File

@ -0,0 +1,10 @@
<h1><%= t('admin.editing_home') %></h1>
<%= form_for @home, :url => admin_home_path(@home) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end %>

View File

@ -0,0 +1,11 @@
<h1><%= t('admin.new_home') %></h1>
<%= form_for :home, :url => admin_homes_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end %>

View File

@ -7,5 +7,5 @@
<td> <td>
<%= link_to t(:show), item.url %> | <%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_component_path(item) %> | <%= link_to t(:edit), edit_admin_component_path(item) %> |
<%= link_to t(:delete), admin_component_path(item), :confirm => 'Are you sure?', :method => :delete %> <%= link_to t(:delete), admin_component_path(item), :confirm => t('sure?'), :method => :delete %>
</td> </td>

View File

@ -0,0 +1,10 @@
<td><%= item.class %></td>
<td><%= link_to item.name, admin_items_path(:parent_id => item.id) %></td>
<td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%= item.position %></td>
<td><%= item.is_published.to_s %></td>
<td>
<%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_home_path(item) %> |
<%= link_to t(:delete), admin_home_path(item), :confirm => t('sure?'), :method => :delete %>
</td>

View File

@ -1,11 +1,10 @@
<td><%= item.class %></td>
<td><%= item.class %></td> <td><%= item.name %></td>
<td><%= link_to item.name, admin_items_path(:parent_name => item.name) %></td> <td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%=h item.title %> <td><%= item.position %></td>
<td><%= item.position %></td> <td><%= item.is_published.to_s %></td>
<td><%= item.is_published.to_s %></td> <td>
<td> <%= link_to t(:show), item.url %> |
<%= link_to t(:show), item.url %> | <%= link_to t(:edit), edit_admin_link_path(item) %> |
<%= link_to t(:edit), edit_admin_link_path(item) %> | <%= link_to t(:delete), admin_link_path(item), :confirm => t('sure?'), :method => :delete %>
<%= link_to t(:delete), admin_link_path(item), :confirm => 'Are you sure?', :method => :delete %> </td>
</td>

View File

@ -1,11 +1,11 @@
<td><%= item.class %></td> <td><%= item.class %></td>
<td><%= link_to item.name, admin_items_path(:parent_name => item.name) %></td> <td><%= link_to item.name, admin_items_path(:parent_id => item.id) %></td>
<td><%=h item.title %> <td><%= item.i18n_variable[I18n.locale] rescue nil %>
<td><%= item.position %></td> <td><%= item.position %></td>
<td><%= item.is_published.to_s %></td> <td><%= item.is_published.to_s %></td>
<td> <td>
<%= link_to t(:show), item.url %> | <%= link_to t(:show), item.url %> |
<%= link_to t(:edit), edit_admin_page_path(item) %> | <%= link_to t(:edit), edit_admin_page_path(item) %> |
<%= link_to t(:delete), admin_page_path(item), :confirm => 'Are you sure?', :method => :delete %> <%= link_to t(:delete), admin_page_path(item), :confirm => t('sure?'), :method => :delete %>
</td> </td>

View File

@ -1,4 +1,4 @@
<h1>Listing snippets</h1> <h1><%= t('admin.list_snippets') %></h1>
<table> <table>
<tr> <tr>
@ -9,7 +9,7 @@
<td><%= snippet.name %></td> <td><%= snippet.name %></td>
<td><%= link_to t(:show), admin_snippet_path(snippet) %> <td><%= link_to t(:show), admin_snippet_path(snippet) %>
<td><%= link_to t(:edit), edit_admin_snippet_path(snippet) %></td> <td><%= link_to t(:edit), edit_admin_snippet_path(snippet) %></td>
<td><%= link_to t(:delete), admin_snippet_path(snippet), :confirm => 'Are you sure?', :method => :delete %></td> <td><%= link_to t(:delete), admin_snippet_path(snippet), :confirm => t('sure?'), :method => :delete %></td>
</tr> </tr>
<% end %> <% end if snippets%>
</table> </table>

View File

@ -1,32 +1,44 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<ul class="list"> <ul class="list">
<li><%= link_to t(:new_page, :scope => :admin), new_admin_page_path( :parent_name => @parent_item.name ), :class => 'button positive' %></li> <% if (@items.empty? && !@parent_item ) || (!@items.empty? && @items[0].is_home?) %>
<li><%= link_to t(:new_link, :scope => :admin), new_admin_link_path( :parent_name => @parent_item.name ) %> <li><%= t('admin.new_page') %></li>
<li><%= link_to t(:new_snippet, :scope => :admin ), new_admin_snippet_path( :parent_name => @parent_item.name ), :class => 'button positive' %></li> <li><%= t('admin.new_link') %></li>
</ul> <li><%= t('admin.new_snippet') %></li>
<% else %>
<li><%= link_to t('admin.new_page'), new_admin_page_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
<li><%= link_to t('admin.new_link'), new_admin_link_path( :parent_id => @parent_item.id ) %>
<li><%= link_to t('admin.new_snippet'), new_admin_snippet_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
<% end %>
</ul>
<% end -%> <% end -%>
<h1>Listing items: <%= show_parent_items_link(@parent_item) %></h1> <h1><%= t('admin.list_items') %>: <%= show_parent_items_link unless @parent_item.nil? %></h1>
<table> <% if !Layout.exist_one? %>
<tr> <div style='color:red'><%= t('admin.no_layout') %>: <%= link_to t('create').downcase, new_admin_layout_path %></div>
<th>Class</th> <br/>
<th>Name</th> <% elsif (@items.empty? && !@parent_item ) %>
<th>Title</th> <div style='color:red'><%= t('admin.no_home_page') %>: <%= link_to t('create').downcase, new_admin_home_path(:parent_id => nil) %></div>
<th>Position</th> <br/>
<th>Published?</th> <% else %>
<th>Action</th> <table>
<th></th> <tr>
</tr> <th><%= t('admin.class') %></th>
<th><%= t('admin.name') %></th>
<% @items.each do |item| %> <th><%= t('admin.title') %></th>
<tr> <th><%= t('admin.position') %></th>
<%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %> <th><%= t('admin.published?') %></th>
<!--<td><%= link_to t(:move_up, :scope => :admin), up_admin_item_path(item), :method => :put %> | <th><%= t('admin.action') %></th>
<%= link_to t(:move_down, :scope => :admin), down_admin_item_path(item), :method => :put %></td>--> <th></th>
</tr> </tr>
<% @items.each do |item| %>
<tr>
<%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %>
<!--<td><%= link_to t(:move_up, :scope => :admin), up_admin_item_path(item), :method => :put %> |
<%= link_to t(:move_down, :scope => :admin), down_admin_item_path(item), :method => :put %></td>-->
</tr>
<% end if @items %>
</table>
<% end %> <% end %>
</table>
<%= render :partial => "snippets", :locals => { :snippets => @snippets } %> <%= render :partial => "snippets", :locals => { :snippets => @snippets } %>

View File

@ -1,30 +1,14 @@
<p> <p>
<%= f.label :name, "Name" %> <%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text' %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p> <p>
<%= f.label :description, "Description" %> <%= f.label :description, t('admin.description') %>
<%= f.text_field :description, :class => 'text' %> <%= f.text_field :description, :class => 'text' %>
</p> </p>
<p id="content_zh_tw_block"> <p>
<%= f.label "content_zh_tw", "Content (zh_tw)" %> <%= f.label "content", t('admin.content') %>
<%= f.text_area "content_zh_tw", :size => '100x30' %> <%= f.text_area :content, :size => '100x30' %>
</p> </p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>

View File

@ -1,12 +1,9 @@
<h1>Editing layouts</h1> <h1><%= t('admin.editing_layout') %></h1>
<% form_for @layout, :url => admin_layout_path(@layout) do |f| %> <%= form_for @layout, :url => admin_layout_path(@layout) do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Update' %> <%= f.submit t('update') %> <%= link_back %>
</p> </p>
<% end %> <% end %>
<%= link_to 'Back', admin_layouts_path %>

View File

@ -1,19 +1,26 @@
<h1>Listing layouts</h1> <% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:new_layout, :scope => :admin), new_admin_layout_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_layouts') %></h1>
<table> <table>
<tr> <tr>
<th><%= t('admin.name') %></th>
<th><%= t('admin.description') %></th>
<th><%= t('admin.action') %></th>
</tr> </tr>
<% @layouts.each do |layout| %> <% @layouts.each do |layout| %>
<tr> <tr>
<td><%= layout.name %></td> <td><%= layout.name %></td>
<td><%= layout.description %></td> <td><%= layout.description %></td>
<td><%= link_to t(:edit), edit_admin_layout_path(layout) %></td> <td>
<td><%= link_to t(:delete), admin_layout_path(layout), :confirm => 'Are you sure?', :method => :delete %></td> <%= link_to t(:edit), edit_admin_layout_path(layout) %> |
<%= link_to t(:delete), admin_layout_path(layout), :confirm => t('sure?'), :method => :delete %>
</td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<br />
<%= link_to t(:new_layout, :scope => :admin), new_admin_layout_path, :class => 'button positive' %>

View File

@ -1,13 +1,10 @@
<h1>New layouts</h1> <h1><%= t('admin.new_layout') %></h1>
<% form_for :layout, :url => admin_layouts_path do |f| %> <%= form_for :layout, :url => admin_layouts_path do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Create' %> <%= f.submit t('create') %> <%= link_back %>
</p> </p>
<% end %> <% end %>
<%= link_to 'Back', admin_layouts_path %>

View File

@ -1,28 +1,24 @@
<%= f.error_messages %> <%= f.error_messages %>
<%= f.hidden_field :parent_name %> <%= f.hidden_field :parent_id %>
<p> <p>
<%= f.label :name, "Name" %> <%= f.label :name, "Name" %>
<%= f.text_field :name, :class => 'text' %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p> <% @site_valid_locales.each do |locale| %>
<%= f.label :title, "Title en" %> <p>
<%= f.text_field :title_en, :class => 'text' %> <%= label_tag "link[title]", "#{t('admin.title')} #{locale}" %>
</p> <%= text_field_tag "link[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p> <p>
<%= f.label :title, "Title zh_tw" %> <%= f.label :is_published, t('admin.is_published') %>
<%= f.text_field :title_zh_tw, :class => 'text' %>
</p>
<p>
<%= f.label :is_published, "Is Published" %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No <%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p> </p>
<p> <p>
<%= f.label :url, "URL" %> <%= f.label :url, "URL" %>
<%= f.text_field :url %> <%= f.text_field :url %>
</p> </p>

View File

@ -1,10 +1,10 @@
<h1>Editing pages</h1> <h1><%= t('admin.editing_link') %></h1>
<% form_for @link, :url => admin_link_path(@link) do |f| %> <%= form_for @link, :url => admin_link_path(@link) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Update' %> <%= f.submit t(:update) %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -1,11 +1,11 @@
<h1><%= t(:new_link, :scope => :admin) %></h1> <h1><%= t('admin.new_link') %></h1>
<% form_for @link, :url => admin_links_path do |f| %> <%= form_for @link, :url => admin_links_path do |f| %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Create' %> <%= f.submit t(:create) %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -1,49 +1,34 @@
<%= f.error_messages %> <%= f.hidden_field :parent_id %>
<%= f.hidden_field :parent_name %>
<p> <p>
<%= f.label :name, "Name" %> <%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text' %> <% if @page.parent_id.nil? %>
</p> <%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
<%= f.hidden_field :name, :value => 'home' %>
<p> <% else %>
<%= f.label :title, "Title en" %> <%= f.text_field :name, :class => 'text' %>
<%= f.text_field :title_en, :class => 'text' %> <% end %>
</p> </p>
<p> <% @site_valid_locales.each do |locale| %>
<%= f.label :title, "Title zh_tw" %> <p>
<%= f.text_field :title_zh_tw, :class => 'text' %> <%= label_tag "#{f}[title]", "#{t('admin.title')} #{locale}" %>
</p> <%= text_field_tag "#{f}[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
</p>
<% end %>
<p> <p>
<%= f.label :layout_name, "Layout Name" %> <%= f.label :layout_name, t('admin.layout_name') %>
<%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %> <%= f.select :layout_name, Layout.all.map{ |l| [l.description, l.name] } %>
</p> </p>
<p id="content_zh_tw_block"> <p>
<%= f.label "content_zh_tw", "Content (zh_tw)" %> <%= f.label "content", t('admin.content') %>
<%= f.text_area "content_zh_tw", :size => '100x30' %> <%= f.text_area "content", :size => '100x30' %>
</p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p> </p>
<p> <p>
<%= f.label :is_published, "Is Published" %> <%= f.label :is_published, "#{t('admin.is_published')} ?" %>
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No <%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
</p> </p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>

View File

@ -1,10 +1,11 @@
<h1>Editing pages</h1> <h1><%= t('admin.editing_page') %></h1>
<% form_for @page, :url => admin_page_path(@page) do |f| %>
<%= form_for @page, :url => admin_page_path(@page) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Update' %> <%= f.submit t('update') %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -1,11 +1,11 @@
<h1>New pages</h1> <h1><%= t('admin.new_page') %></h1>
<% form_for :page, :url => admin_pages_path do |f| %>
<%= form_for :page, :url => admin_pages_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Create' %> <%= f.submit t('create') %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -1,28 +1,11 @@
<%= f.error_messages %> <%= f.hidden_field :parent_id %>
<%= f.hidden_field :parent_name %>
<p> <p>
<%= f.label :name, "Name" %> <%= f.label :name, t('admin.name') %>
<%= f.text_field :name, :class => 'text' %> <%= f.text_field :name, :class => 'text' %>
</p> </p>
<p id="content_zh_tw_block"> <p>
<%= f.label "content_zh_tw", "Content (zh_tw)" %> <%= f.label "content", t('admin.content') %>
<%= f.text_area "content_zh_tw", :size => '100x30' %> <%= f.text_area "content", :size => '100x30' %>
</p> </p>
<p><a href="#" id="toggle_content_en_block">Edit english</a></p>
<p id="content_en_block">
<%= f.label "content_en", "Content (en)" %>
<%= f.text_area "content_en", :size => '100x30' %>
</p>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#content_en_block').hide();
$('#toggle_content_en_block').click(function(){
$('#content_en_block').toggle();
});
</script>
<% end -%>

View File

@ -1,11 +1,11 @@
<h1>Editing snippets</h1> <h1><%= t('admin.editing_snippet') %></h1>
<% form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %> <%= form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Update' %> <%= f.submit 'Update' %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -1,4 +1,4 @@
<h1>New snippets</h1> <h1><%= t('admin.new_snippet') %></h1>
<% form_for :snippet, :url => admin_snippets_path do |f| %> <% form_for :snippet, :url => admin_snippets_path do |f| %>
<%= f.error_messages %> <%= f.error_messages %>
@ -6,6 +6,6 @@
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<p> <p>
<%= f.submit 'Create' %> <%= f.submit t('create') %> <%= link_back %>
</p> </p>
<% end %> <% end %>

View File

@ -0,0 +1 @@
<a href="#" class="edit"><%= t(:edit) %></a> | <a href="#" class="hide"><%= t(:hide) %></a>

View File

@ -0,0 +1,16 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% @language_i18n_variables.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{var.id}][#{locale}]", var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,34 @@
<% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(edit_user_attribute_model.id.to_s)
result
end %>
<fieldset>
<legend>
<%= edit_user_attribute_model.key %>
<%#= render :partial => 'action_bar' %>
</legend>
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= edit_user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{edit_user_attribute_model.id}][#{locale}]", edit_user_attribute_model[locale] %></td>
<% end %>
</tr>
<% @vars.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "i18n_variables[#{var.id}][#{locale}]", var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
</fieldset>

View File

@ -0,0 +1,16 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% @language_i18n_variables.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,34 @@
<% @vars = @i18n_variables.inject([]) do |result, var|
result << var if var.parent_id.to_s.eql?(user_attribute_model.id.to_s)
result
end %>
<fieldset>
<legend>
<%= user_attribute_model.key %>
<%#= render :partial => 'action_bar' %>
</legend>
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= user_attribute_model[locale] %></td>
<% end %>
</tr>
<% @vars.each do |var| %>
<tr>
<td><%= var.key %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= var[locale] %></td>
<% end %>
</tr>
<% end %>
</table>
</fieldset>

View File

@ -0,0 +1,25 @@
<%= form_tag admin_translation_path('all'), :method => :put do %>
<% if @language_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.language') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'edit_language' %></div>
</fieldset>
<% end %>
<% if @user_attribute_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_attribute') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'edit_user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
</fieldset>
<% end %>
<%= submit_tag t('update') %> <%= link_back %>
<% end %>

View File

@ -0,0 +1,69 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t(:edit), edit_admin_translation_path('all'), :class => 'button positive' %></li>
<li>
<%= t('admin.add_language') %>:
<%= form_tag admin_translation_path('add'), :method => :put do %>
<%= text_field_tag 'language', '', :style => "width:100px" %>
<%= submit_tag t(:add) %>
<% end %>
</li>
<li>
<%= t('admin.enable_language') %>:
<%= form_tag admin_translation_path('enable'), :method => :put do %>
<%= select_tag 'enable_language', options_for_select(@site_valid_locales - @site_in_use_locales), :style => "width:100px" %>
<%= submit_tag t(:enable) %>
<% end %>
</li>
<li>
<%= t('admin.disable_language') %>:
<%= form_tag admin_translation_path('disable'), :method => :put do %>
<%= select_tag 'disable_language', options_for_select(@site_in_use_locales), :style => "width:100px" %>
<%= submit_tag t(:disable) %>
<% end %>
</li>
<li>
<%= t('admin.delete_language') %>:
<%= form_tag admin_translation_path('delete'), :method => :put do %>
<%= select_tag 'delete_language', options_for_select(@site_valid_locales), :style => "width:100px" %>
<%= submit_tag t(:delete), :confirm => t('sure?') %>
<% end %>
</li>
</ul>
<% end -%>
<% if @language_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.language') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'language' %></div>
</fieldset>
<% end %>
<% if @user_attribute_model_i18n_variables.size > 0 %>
<fieldset>
<legend>
<%= t('admin.user_attribute') %>
<%#= render :partial => 'action_bar' %>
</legend>
<div><%= render :partial => 'user_attribute_model', :collection => @user_attribute_model_i18n_variables %></div>
</fieldset>
<% end %>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('div a.hide').live( "click", function(){
$(this).parent().next().hide();
$(this).replaceWith("<a href='#' class='show'><%= t(:show) %></a>");
});
$('div a.show').live( "click", function(){
$(this).parent().next().show();
$(this).replaceWith("<a href='#' class='hide'><%= t(:hide) %></a>");
});
</script>
<% end -%>

View File

@ -0,0 +1,30 @@
<%= fields_for 'user_attribute_model[attribute_attr_models][]', attribute_attr_model, :index => nil do |f| %>
<tr>
<td><%= attribute_attr_model.new_record? ? (f.text_field :key, {:style => "width:130px"}) : attribute_attr_model.key %></td>
<td class='select_mulitlingual' style='text-align:center'>
<%= check_box_tag "locale[]", value = '', attribute_attr_model.locale.nil? ? true : attribute_attr_model.locale %>
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][locale]", attribute_attr_model.locale.nil? ? true : attribute_attr_model.locale %>
</td>
<% @site_valid_locales.each do |locale| %>
<td><%= text_field_tag "user_attribute_model[attribute_attr_models][][i18n_variable][#{locale}]", (attribute_attr_model.i18n_variable[locale] rescue nil), :style => "width:130px" %></td>
<% end %>
<td class='select_type'>
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
<div <%= attribute_attr_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
<%= t('admin.options') %>:
<%= text_field_tag "user_attribute_model[attribute_attr_models][][select_options]", attribute_attr_model.select_options, :style => "width:130px" %>
</div>
</td>
<td>
<% if attribute_attr_model.new_record? %>
<a href="#" class="remove">(<%= t(:delete) %>)</a>
<% else %>
<a href="#" class="remove_existing_record">(<%= t(:delete) %>)</a>
<%= hidden_field_tag "user_attribute_model[attribute_attr_models][][should_destroy]", nil , :class => 'should_destroy' %>
<%= f.hidden_field :id %>
<% end %>
</td>
</tr>
<% end %>

View File

@ -0,0 +1,73 @@
<table>
<tr>
<th><%= t('admin.key') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<tr>
<td><%= is_new ? (f.text_field :key, {:style => "width:130px"}) : @user_attribute_model.key %></td>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user_attribute_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:130px" %>
</td>
<% end %>
</tr>
</table>
<fieldset id='field_set_attribute_attrs'>
<legend>
<%= t('admin.attributes')%>
</legend>
<table id='attribute_attrs'>
<tr>
<th><%= t('admin.key') %></th>
<th><%= t('admin.multilingual') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
<th><%= t('admin.type')%></th>
<th></th>
</tr>
<%= render :partial => 'attribute_attr_model', :collection => @user_attribute_model.attribute_attr_models %>
</table>
<a href="#" class="add">(<%= t(:add) %>)</a>
</fieldset>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
$('#field_set_attribute_attrs a.remove').live('click', function(){
$(this).parent().parent().remove();
});
$('#field_set_attribute_attrs a.add').click(function(){
$('#attribute_attrs').append("<%= escape_javascript(render(:partial => 'attribute_attr_model', :object => @user_attribute_model.attribute_attr_models.build)) %>");
});
$('#field_set_attribute_attrs a.remove_existing_record').click(function(){
$(this).next('.should_destroy').attr('value', 1);
$(this).parent().parent().hide();
});
$('.select_mulitlingual input').live('click', function(){
$(this).next().attr('value', this.checked);
});
$('.select_type select').live('change', function(){
if(this.value == 'select')
{
$(this).next().show();
}
else
{
$(this).next().hide();
}
});
</script>
<% end -%>

View File

@ -0,0 +1,19 @@
<h1><%= t('admin.editing_user_attribute') %>: <%= @user_attribute_model.key %></h1>
<fieldset>
<legend>
<%= t('admin.user_attribute')%>
</legend>
<%= form_for @user_attribute_model, :url => admin_user_attribute_model_path(@user_attribute_model) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => false } %>
<p>
<%= f.submit t('update') %> <%= link_back %>
</p>
<% end -%>
</fieldset>

View File

@ -0,0 +1,26 @@
<% content_for :secondary do %>
<ul class="list">
<li><%= link_to t('admin.new_user_attribute'), new_admin_user_attribute_model_path, :class => 'button positive' %></li>
</ul>
<% end -%>
<h1><%= t('admin.list_user_attributes') %></h1>
<table>
<tr>
<th><%= t('admin.attribute') %></th>
<th><%= t('admin.key') %></th>
<th><%= t('admin.action') %></th>
</tr>
<% @user_attribute_models.each do |user_attribute_model| %>
<tr>
<td><%= user_attribute_model.i18n_variable[I18n.locale] %></td>
<td><%= user_attribute_model.key %></td>
<td>
<%= link_to t(:edit), edit_admin_user_attribute_model_path(user_attribute_model) %> |
<%= link_to t(:delete), admin_user_attribute_model_path(user_attribute_model), :confirm => t('sure?'), :method => :delete %>
</td>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,19 @@
<h1><%= t('admin.new_user_attribute') %></h1>
<fieldset id='field_set_attribute_attrs'>
<legend>
<%= t('admin.user_attribute')%>
</legend>
<%= form_for @user_attribute_model, :url => admin_user_attribute_models_path do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f, :is_new => true } %>
<p>
<%= f.submit t('create') %> <%= link_back %>
</p>
<% end -%>
</fieldset>

View File

@ -0,0 +1,9 @@
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>

View File

@ -0,0 +1,9 @@
<% if user_signed_in? %>
<li>
<%= link_to('Edit registration', edit_user_registration_path) %>
</li>
<% else %>
<li>
<%= link_to('Register', new_user_registration_path) %>
</li>
<% end %>

View File

@ -0,0 +1,7 @@
<%= raw(VALID_LOCALES.map{ |locale|
if I18n.locale.to_s.eql?(locale)
t(:_locale, :locale => locale)
else
link_to t(:_locale, :locale => locale), params.merge({:locale => locale})
end
}.join(' | ')) %>

View File

@ -5,7 +5,7 @@
<title>R4</title> <title>R4</title>
<link rel="shortcut icon" href="/favicon.ico"> <link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %> <%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", :media => "screen, projection" %> <%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %> <%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]> <!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %> <%= stylesheet_link_tag "ie", :media => "screen, projection" %>
@ -15,16 +15,27 @@
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<div id="banner_link" style='text-align:right'>
<ul class="hmenu">
<li>
<%= render 'layouts/lang_menu' %>
</li>
<%= render 'devise/menu/login_items' %>
</ul>
</div>
<div id="header"> <div id="header">
<h1>RulingSite Admin</h1> <h1>RulingSite <%= t('admin.admin') %></h1>
<ul id="nav"> <ul id="nav">
<li><%= link_to t(:home, :scope => :admin), root_path %></li> <li><%= link_to t('homepage'), root_path %></li>
<li><%= link_to t(:item, :scope => :admin), admin_items_path %></li> <li><%= link_to t('admin.item'), admin_items_path %></li>
<li><%= link_to t(:layout, :scope => :admin), admin_layouts_path %></li> <li><%= link_to t('admin.layout'), admin_layouts_path %></li>
<li><%= link_to t(:asset, :scope => :admin), admin_assets_path %></li> <li><%= link_to t('admin.asset'), admin_assets_path %></li>
<li><%= link_to t(:user_attribute, :scope => :admin), admin_user_attributes_path %></li> <li><%= link_to t('admin.user_attribute'), admin_user_attribute_models_path %></li>
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
</ul> </ul>
</div> </div>
@ -46,4 +57,4 @@
"application", :cache => 'all' %> "application", :cache => 'all' %>
<%= yield :page_specific_javascript %> <%= yield :page_specific_javascript %>
</body> </body>
</html> </html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>R4</title>
<link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
<![endif]-->
<%= yield :page_specific_css %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="container">
<ul class="hmenu">
<%= render 'devise/menu/registration_items' %>
<%= render 'devise/menu/login_items' %>
</ul>
<div id="header">
<h1>RulingSite</h1>
</div>
<div class="content">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<div class="main"><%= yield %></div>
<div class="secondary"><%= yield :secondary %></div>
<div class="tertiary"><%= yield :tertiary %></div>
</div>
<div id="footer">
<p>Rulingcom</p>
</div>
</div>
<%#= javascript_include_tag "jquery",
"jquery-ui",
"rails",
"easy",
"application", :cache => 'all' %>
<%= yield :page_specific_javascript %>
</body>
</html>

View File

@ -5,7 +5,7 @@
<title>R4</title> <title>R4</title>
<link rel="shortcut icon" href="/favicon.ico"> <link rel="shortcut icon" href="/favicon.ico">
<%= yield :page_specific_link %> <%= yield :page_specific_link %>
<%= stylesheet_link_tag "easy", "main", :media => "screen, projection" %> <%= stylesheet_link_tag "easy", "main", "devise", :media => "screen, projection" %>
<%= stylesheet_link_tag "easyprint", :media => "print" %> <%= stylesheet_link_tag "easyprint", :media => "print" %>
<!--[if IE]> <!--[if IE]>
<%= stylesheet_link_tag "ie", :media => "screen, projection" %> <%= stylesheet_link_tag "ie", :media => "screen, projection" %>
@ -15,13 +15,23 @@
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<div id="banner_link" style='text-align:right'>
<ul class="hmenu">
<li>
<%= render 'layouts/lang_menu' %>
</li>
<%= render 'devise/menu/login_items' %>
</ul>
</div>
<div id="header"> <div id="header">
<h1>RulingSite Panel</h1> <h1>RulingSite Panel</h1>
<ul id="nav"> <ul id="nav">
<li><%= link_to t(:home, :scope => :panel), root_path %></li> <li><%= link_to t('panel.home'), root_path %></li>
<li><%= link_to t(:users, :scope => :panel), panel_users_path %></li> <li><%= link_to t('panel.user'), panel_users_path %></li>
</ul> </ul>
</div> </div>
@ -43,4 +53,4 @@
"application", :cache => 'all' %> "application", :cache => 'all' %>
<%= yield :page_specific_javascript %> <%= yield :page_specific_javascript %>
</body> </body>
</html> </html>

View File

@ -0,0 +1,25 @@
<%= fields_for 'user[user_attributes][attribute_attrs]', attribute_attr, :index => nil do |f| %>
<%#= f.hidden_field :id unless attribute_attr.new_record? %>
<% if attr["locale"] %>
<p>
<%#= f.hidden_field :key, :value => attr["key"] %>
<% if attr["markup"] == "text_field" %>
<% @site_valid_locales.each do |locale| %>
<%= f.label attr.i18n_variable[locale] %>
<%= text_field_tag "user[user_attributes][attribute_attrs][i18n_user][#{locale}]", (attribute_attr.i18n_user[locale] rescue nil) %>
<% end -%>
<% elsif attr["markup"] == "select" %>
<%= f.select "#{attr["key"]}_#{I18n.locale}", attr["options_#{I18n.locale}"].to_a %>
<% end -%>
</p>
<% else %>
<p>
<%= f.label attr["name"] %>
<% if attr["markup"] == "text_field" %>
<%= f.text_field "#{attr["key"]}" %>
<% elsif attr["markup"] == "select" %>
<%= f.select "#{attr["key"]}", attr["options"].to_a %>
<% end -%>
</p>
<% end -%>
<% end %>

View File

@ -1,47 +1,28 @@
<div id="select_user_attributes"> <div id="select_user_attributes">
<% @user_attributes.each do |ua| %> <% @user_attribute_models.each do |ua| %>
<%= check_box_tag "user[use_attributes][]", ua.key, @user.use_attributes.include?(ua.key) %> <%= ua.name %> <%= check_box_tag "user[active_attributes][]", ua.key, (@user.active_attributes.include?(ua.key) rescue false) %> <%= ua.i18n_variable[locale] %>
<% end -%> <% end -%>
<%= hidden_field_tag 'user[use_attributes][]','' %> <%= hidden_field_tag 'user[active_attributes][]', '' %>
</div> </div>
<div> <div>
<p> <label><%= t('panel.my_avatar') %></label>
<%= f.label :email %> <%= image_tag(@user.avatar.thumb.url) if @user.avatar? %>
<%= f.text_field :email %> <%= file_field_tag 'file' %>
</p> <%= hidden_field_tag :avatar_cache %>
</div> </div>
<% @user_attributes.each do |ua| %> <div>
<div id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless @user.use_attributes.include?(ua.key) %>> <p>
<h3><%= ua.name %></h3> <%= f.label :email %>
<%= f.text_field :email %>
<% ua.attrs.each do |attr| %> </p>
<% if attr["locale"] %>
<p>
<%= f.label attr["name_#{I18n.locale}"] %>
<% if attr["type"] == "text_field" %>
<% VALID_LOCALES.each do |locale| %>
<%= f.text_field "#{ua.key}_#{attr["key"]}_#{locale}" %>(<%= locale %>)
<% end -%>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}_#{I18n.locale}", attr["options_#{I18n.locale}"].to_a %>
<% end -%>
</p>
<% else %>
<p>
<%= f.label attr["name"] %>
<% if attr["type"] == "text_field" %>
<%= f.text_field "#{ua.key}_#{attr["key"]}" %>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}", attr["options"].to_a %>
<% end -%>
</p>
<% end -%>
<% end -%>
</div> </div>
<% @user_attribute_models.each do |ua| %>
<%= render :partial => 'user_attribute',
:object => (@user.user_attributes.detect {|u| u.key == ua.key } || @user.user_attributes.build),
:locals => {:ua => ua} %>
<% end -%> <% end -%>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
@ -52,4 +33,4 @@
}); });
}); });
</script> </script>
<% end -%> <% end -%>

View File

@ -0,0 +1,42 @@
<fieldset id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless (@user.active_attributes.include?(ua.key) rescue nil) %>>
<%= fields_for 'user[user_attributes]', user_attribute, :index => nil do |f| %>
<legend><%= ua.i18n_variable[I18n.locale] %></legend>
<%= f.hidden_field :key, :value => ua.key %>
<%= f.hidden_field :id unless user_attribute.new_record? %>
<table>
<tr>
<th><%= t('admin.attribute') %></th>
<% @site_valid_locales.each do |locale| %>
<th style="color:<%= colorize_in_use_locale(locale) %>"><%= locale %></th>
<% end %>
</tr>
<% ua.attribute_attr_models.each do |attr| %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<% @site_valid_locales.each do |locale| %>
<td>
<%= text_field_tag "user[user_attributes][][#{attr.key}_#{locale}]", (user_attribute["#{attr.key}_#{locale}"] rescue nil) %>
</td>
<% end -%>
<% else %>
<td colspan=<%= @site_valid_locales.size %>>
<% if attr["markup"] == "text_field" %>
<%= text_field_tag "user[user_attributes][][#{attr.key}]", (user_attribute[attr.key] rescue nil) %>
<% elsif attr["markup"] == "select" %>
<%= select_tag "user[user_attributes][][#{attr.key}]", options_for_select(attr["options"], user_attribute[attr.key]) %>
<% end -%>
</td>
<% end -%>
</tr>
<% end %>
</table>
<% end %>
</fieldset>

View File

@ -4,15 +4,14 @@
</ul> </ul>
<% end -%> <% end -%>
<h1>Users panel</h1> <h1><%= t('panel.user_panel') %></h1>
<% form_for @user, :url => panel_user_path(@user) do |f| %>
<%= form_for @user, :url => panel_user_path(@user), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %> <%= render :partial => 'form', :locals => { :f => f } %>
<p> <p>
<%= f.submit %> <%= f.submit t(:update) %> <%= link_back %>
</p> </p>
<% end -%> <% end -%>

View File

@ -1,29 +1,28 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<ul class="list"> <ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li> <li><%= link_to t('panel.new_user'), new_panel_user_path, :class => 'button positive' %></li>
</ul> </ul>
<% end -%> <% end -%>
<h1>Users panel</h1> <h1><%= t('panel.list_users') %></h1>
<table> <table>
<tr> <tr>
<th>Attrs</th> <th><%= t('panel.attributes') %></th>
<th>Name</th> <th><%= t('panel.name') %></th>
<th>Email</th> <th><%= t('panel.email') %></th>
<th>Action</th> <th><%= t('panel.action') %></th>
</tr> </tr>
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= user.use_attributes.join(",") %></td> <td><%= user.get_attributes %></td>
<td><%= user.name %></td> <td><%= user[:name] %></td>
<td><%= user.email %></td> <td><%= user.email %></td>
<td> <td>
<%= link_to 'Show', panel_user_path(user) %> <%= link_to t(:show), panel_user_path(user) %> |
<%= link_to 'Edit', edit_panel_user_path(user) %> | <%= link_to t(:edit), edit_panel_user_path(user) %> |
<%= link_to 'Destroy', panel_user_path(user), :method => :delete %></td> <%= link_to t(:delete), panel_user_path(user), :method => :delete %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>

View File

@ -1,18 +1,18 @@
<% content_for :secondary do %> <% content_for :secondary do %>
<ul class="list"> <ul class="list">
<li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li> <li><%= link_to t(:new_user, :scope => :panel), new_panel_user_path, :class => 'button positive' %></li>
</ul> </ul>
<% end -%> <% end -%>
<h1>Users panel</h1> <h1><%= t('panel.user_panel') %></h1>
<% form_for @user, :url => panel_users_path do |f| %> <%= form_for @user, :url => panel_users_path, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %> <%= render :partial => 'form', :locals => { :f => f } %>
<p> <p>
<%= f.submit %> <%= f.submit t(:create) %> <%= link_back %>
</p> </p>
<% end -%> <% end -%>

View File

@ -4,7 +4,29 @@
</ul> </ul>
<% end -%> <% end -%>
<h1>Users panel</h1> <h1><%= t('panel.user_panel') %></h1>
<%=h @user.name %> <%= image_tag(@user.avatar.thumb.url) rescue nil %>
<%=h @user.email %>
<%= @user.email %>
<% @user.get_active_attribute_models.each do |am| %>
<% user_attribute = @user.get_attribute_from_model_key(am.key) %>
<fieldset>
<legend><%= am.i18n_variable[I18n.locale] %></legend>
<table>
<% am.attribute_attr_models.each do |attr| %>
<tr>
<td><%= attr.i18n_variable[I18n.locale] %></td>
<td>
<% if attr["locale"] && attr["markup"] == 'text_field' %>
<%= user_attribute["#{attr.key}_#{I18n.locale}"] %>
<% else %>
<%= user_attribute["#{attr.key}"] %>
<% end %>
</td>
</tr>
<% end %>
</table>
</fieldset>
<% end -%>

View File

@ -0,0 +1 @@
<%= @title %>

View File

@ -0,0 +1 @@
<%= @site.inspect %>

View File

@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__) require ::File.expand_path('../config/environment', __FILE__)
run R4::Application run PrototypeR4::Application

View File

@ -4,49 +4,49 @@ require File.expand_path('../boot', __FILE__)
# require "active_record/railtie" # require "active_record/railtie"
require "action_controller/railtie" require "action_controller/railtie"
require "action_mailer/railtie" require "action_mailer/railtie"
# require "active_resource/railtie" require "active_resource/railtie"
# require "rails/test_unit/railtie" require "rails/test_unit/railtie"
require File.expand_path('lib/reroute_middleware') require File.expand_path('lib/reroute_middleware')
# Auto-require default libraries and those for the current Rails environment. # If you have a Gemfile, require the gems listed there, including any gems
Bundler.require :default, Rails.env # you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module R4 module PrototypeR4
class Application < Rails::Application class Application < Rails::Application
config.middleware.use RerouteMiddleware config.middleware.use RerouteMiddleware
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs # Custom directories with classes and modules you want to be autoloadable.
# config.load_paths += %W( #{config.root}/extras ) # config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named # :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running # Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Taipei' # config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :zh_tw # config.i18n.default_locale = :de
config.i18n.default_locale = :en
# Configure generators values. Many other options are available, be sure to check the documentation. # JavaScript files you want as :defaults (application.js is always included).
# config.generators do |g| # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
# g.orm :active_record
# g.template_engine :erb # Configure the default encoding used in templates for Ruby 1.9.
# g.test_framework :test_unit, :fixture => true config.encoding = "utf-8"
# end
# Configure sensitive parameters which will be filtered from the log file. # Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters << :password config.filter_parameters += [:password]
end end
end end

View File

@ -1,17 +1,13 @@
# Use Bundler (preferred) require 'rubygems'
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin begin
require File.expand_path('../../.bundle/environment', __FILE__) ENV['BUNDLE_GEMFILE'] = gemfile
rescue LoadError
require 'rubygems'
require 'bundler' require 'bundler'
Bundler.setup Bundler.setup
rescue Bundler::GemNotFound => e
# To use 2.x style vendor/rails and RubyGems STDERR.puts e.message
# STDERR.puts "Try running `bundle install`."
# vendor_rails = File.expand_path('../../vendor/rails', __FILE__) exit!
# if File.exist?(vendor_rails) end if File.exist?(gemfile)
# Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
# end
#
# require 'rubygems'
end

View File

@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__) require File.expand_path('../application', __FILE__)
# Initialize the rails application # Initialize the rails application
R4::Application.initialize! PrototypeR4::Application.initialize!

View File

@ -1,5 +1,5 @@
R4::Application.configure do PrototypeR4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb # Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on # In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development # every request. This slows down response time but is perfect for development
@ -17,4 +17,10 @@ R4::Application.configure do
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
end end

View File

@ -1,5 +1,5 @@
R4::Application.configure do PrototypeR4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb # Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps. # The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests # Code is not reloaded between requests
@ -9,6 +9,15 @@ R4::Application.configure do
config.consider_all_requests_local = false config.consider_all_requests_local = false
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info) # See everything in the log (default is :info)
# config.log_level = :debug # config.log_level = :debug
@ -30,4 +39,11 @@ R4::Application.configure do
# Enable threaded mode # Enable threaded mode
# config.threadsafe! # config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end end

View File

@ -1,5 +1,5 @@
R4::Application.configure do PrototypeR4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb # Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that # test suite. You never need to work with it otherwise. Remember that
@ -14,6 +14,9 @@ R4::Application.configure do
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment # Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = false
@ -26,4 +29,7 @@ R4::Application.configure do
# This is necessary if your schema can't be completely dumped by the schema dumper, # This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types # like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql # config.active_record.schema_format = :sql
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end end

View File

@ -0,0 +1,15 @@
require 'carrierwave/orm/mongoid'
begin
db_config = YAML::load(File.read(File.join(Rails.root, "/config/mongoid.yml")))
rescue
raise IOError, 'config/mongoid.yml could not be loaded'
end
CarrierWave.configure do |config|
config.grid_fs_database = db_config[Rails.env]['database']
config.grid_fs_host = db_config[Rails.env]['host']
config.grid_fs_port = db_config[Rails.env]['port']
config.storage = :grid_fs
config.grid_fs_access_url = "/gridfs"
end

View File

@ -1,24 +1,20 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first # Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models. # four configuration values can also be set straight in your models.
Devise.setup do |config| Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com" config.mailer_sender = "please-change-me@config-initializers-devise.com"
# ==> Configuration for :authenticatable # Configure the class responsible to send e-mails.
# Invoke `rake secret` and use the printed value to setup a pepper to generate # config.mailer = "Devise::Mailer"
# the encrypted password. By default no pepper is used.
# config.pepper = "rake secret output"
# Configure how many times you want the password is reencrypted. Default is 10. # ==> ORM configuration
# config.stretches = 10 # Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# Define which will be the encryption algorithm. Supported algorithms are :sha1 # available as additional gems.
# (default), :sha512 and :bcrypt. Devise also supports encryptors from others require 'devise/orm/mongoid'
# authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
# stretches above to 20 for default behavior) and :restful_authentication_sha1
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
# config.encryptor = :sha1
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating an user. By default is # Configure which keys are used when authenticating an user. By default is
# just :email. You can configure it to use [:username, :subdomain], so for # just :email. You can configure it to use [:username, :subdomain], so for
# authenticating an user, both parameters are required. Remember that those # authenticating an user, both parameters are required. Remember that those
@ -26,33 +22,80 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter. # session. If you need permissions, you should implement that in a before filter.
# config.authentication_keys = [ :email ] # config.authentication_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
# config.http_authenticatable = false
# Set this to true to use Basic Auth for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication # The realm used in Http Basic Authentication
# config.http_authentication_realm = "Application" # config.http_authentication_realm = "Application"
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
config.stretches = 10
# Define which will be the encryption algorithm. Devise also supports encryptors
# from others authentication tools as :clearance_sha1, :authlogic_sha512 (then
# you should set stretches above to 20 for default behavior) and :restful_authentication_sha1
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
config.encryptor = :bcrypt
# Setup a pepper to generate the encrypted password.
config.pepper = "a5a6b41c8a259f0642f9e8a51b77f3c671be92a430e021e00f7e0bcc71381c0698d3c3e9c1dc270872a16ed2703715e3b3b817245740bbb871a3411714944dce"
# ==> Configuration for :confirmable # ==> Configuration for :confirmable
# The time you want give to your user to confirm his account. During this time # The time you want to give your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is nil. # he will be able to access your application without confirming. Default is nil.
# When confirm_within is zero, the user won't be able to sign in without confirming.
# You can use this to let your user access some features of your application
# without confirming the account, but blocking it after a certain period
# (ie 2 days).
# config.confirm_within = 2.days # config.confirm_within = 2.days
# ==> Configuration for :rememberable # ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again. # The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks # config.remember_for = 2.weeks
# If true, a valid remember token can be re-used between multiple browsers.
# config.remember_across_browsers = true
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# ==> Configuration for :validatable
# Range for password length
# config.password_length = 6..20
# Regex to use to validate the email address
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
# ==> Configuration for :timeoutable # ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this # The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. # time the user will be asked for credentials again.
# config.timeout_in = 10.minutes # config.timeout_in = 10.minutes
# ==> Configuration for :lockable # ==> Configuration for :lockable
# Number of authentication tries before locking an account. # Defines which strategy will be used to lock an account.
# config.maximum_attempts = 20 # :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which strategy will be used to unlock an account. # Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email # :email = Sends an unlock link to the user email
# :time = Reanables login after a certain ammount of time (see :unlock_in below) # :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = enables both strategies # :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
# config.unlock_strategy = :both # config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
# config.maximum_attempts = 20
# Time interval to unlock the account if :time is enabled as unlock_strategy. # Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour # config.unlock_in = 1.hour
@ -60,27 +103,30 @@ Devise.setup do |config|
# Defines name of the authentication token params key # Defines name of the authentication token params key
# config.token_authentication_key = :auth_token # config.token_authentication_key = :auth_token
# ==> General configuration # ==> Scopes configuration
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper
# (requires mongo_ext installed) and :data_mapper (experimental).
# require 'devise/orm/mongo_mapper'
config.orm = :mongo_mapper
# Turn scoped views on. Before rendering "sessions/new", it will first check for # Turn scoped views on. Before rendering "sessions/new", it will first check for
# "sessions/users/new". It's turned off by default because it's slower if you # "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views. # are using only default views.
# config.scoped_views = true # config.scoped_views = true
# By default, devise detects the role accessed based on the url. So whenever # Configure the default scope given to Warden. By default it's the first
# accessing "/users/sign_in", it knows you are accessing an User. This makes # devise role declared in your routes.
# routes as "/sign_in" not possible, unless you tell Devise to use the default
# scope, setting true below.
# config.use_default_scope = true
# Configure the default scope used by Devise. By default it's the first devise
# role declared in your routes.
# config.default_scope = :user # config.default_scope = :user
# Configure sign_out behavior.
# By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
# In case of sign_out_all_scopes set to true any logout action will sign out all active scopes.
# config.sign_out_all_scopes = false
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists. Default is [:html]
# config.navigational_formats = [:html, :iphone]
# ==> Warden configuration
# If you want to use other strategies, that are not (yet) supported by Devise, # If you want to use other strategies, that are not (yet) supported by Devise,
# you can configure them inside the config.warden block. The example below # you can configure them inside the config.warden block. The example below
# allows you to setup OAuth, using http://github.com/roman/warden_oauth # allows you to setup OAuth, using http://github.com/roman/warden_oauth
@ -91,12 +137,6 @@ Devise.setup do |config|
# twitter.consumer_key = <YOUR CONSUMER KEY> # twitter.consumer_key = <YOUR CONSUMER KEY>
# twitter.options :site => 'http://twitter.com' # twitter.options :site => 'http://twitter.com'
# end # end
# manager.default_strategies.unshift :twitter_oauth # manager.default_strategies(:scope => :user).unshift :twitter_oauth
# end
# Configure default_url_options if you are using dynamic segments in :path_prefix
# for devise_for.
# config.default_url_options do
# { :locale => I18n.locale }
# end # end
end end

Some files were not shown because too many files have changed in this diff Show More