kuhsaft 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -3
- data/.rspec +4 -0
- data/.rvmrc +47 -0
- data/Gemfile +1 -3
- data/Guardfile +25 -0
- data/Rakefile +28 -2
- data/app/controllers/kuhsaft/admin/assets_controller.rb +41 -0
- data/app/controllers/kuhsaft/admin/pages_controller.rb +54 -0
- data/app/controllers/kuhsaft/pages_controller.rb +11 -0
- data/app/models/kuhsaft/asset.rb +4 -0
- data/app/models/kuhsaft/localized_page.rb +19 -0
- data/app/models/kuhsaft/page.rb +113 -0
- data/app/models/kuhsaft/page_part.rb +12 -0
- data/app/models/kuhsaft/page_parts/base.rb +26 -0
- data/app/models/kuhsaft/page_parts/content.rb +8 -0
- data/app/models/kuhsaft/page_parts/markdown.rb +7 -0
- data/app/stylesheets/kuhsaft/admin/ie.sass +0 -0
- data/app/stylesheets/kuhsaft/admin/partials/_assets.sass +12 -0
- data/app/stylesheets/kuhsaft/admin/partials/_buttons.sass +216 -0
- data/app/stylesheets/kuhsaft/admin/partials/_generic.sass +29 -0
- data/app/stylesheets/kuhsaft/admin/partials/_pages.sass +38 -0
- data/app/stylesheets/kuhsaft/admin/print.sass +0 -0
- data/app/stylesheets/kuhsaft/admin/screen.sass +8 -0
- data/app/uploaders/kuhsaft/asset_uploader.rb +47 -0
- data/app/views/kuhsaft/admin/assets/_form.html.haml +3 -0
- data/app/views/kuhsaft/admin/assets/_list.html.haml +7 -0
- data/app/views/kuhsaft/admin/assets/edit.html.haml +1 -0
- data/app/views/kuhsaft/admin/assets/index.html.haml +3 -0
- data/app/views/kuhsaft/admin/assets/new.html.haml +1 -0
- data/app/views/kuhsaft/admin/pages/_branch.html.haml +10 -0
- data/app/views/kuhsaft/admin/pages/_form.html.haml +11 -0
- data/app/views/kuhsaft/admin/pages/edit.html.haml +1 -0
- data/app/views/kuhsaft/admin/pages/index.html.haml +17 -0
- data/app/views/kuhsaft/admin/pages/new.html.haml +1 -0
- data/app/views/kuhsaft/admin/pages/show.html.haml +0 -0
- data/app/views/kuhsaft/pages/index.html.haml +0 -0
- data/app/views/kuhsaft/pages/show.html.haml +0 -0
- data/app/views/layouts/kuhsaft/admin.html.haml +21 -0
- data/config/initializers/compass.rb +3 -0
- data/config/initializers/generators.rb +7 -0
- data/config/locales/kuhsaft.en.yml +20 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20110302101530_create_kuhsaft_pages.rb +14 -0
- data/db/migrate/20110302113020_create_kuhsaft_localized_pages.rb +19 -0
- data/db/migrate/20110302125123_create_page_part_contents.rb +14 -0
- data/db/migrate/20110307162621_create_assets.rb +12 -0
- data/kuhsaft.gemspec +19 -2
- data/lib/kuhsaft.rb +3 -1
- data/lib/kuhsaft/engine.rb +19 -0
- data/lib/kuhsaft/version.rb +1 -1
- data/public/images/css3buttons_backgrounds.png +0 -0
- data/public/images/css3buttons_icons.png +0 -0
- data/public/images/drag-handle.png +0 -0
- data/public/javascripts/kuhsaft/admin/jquery-1.4.4.js +7179 -0
- data/public/javascripts/kuhsaft/admin/jquery-ui-1.8.10.custom.min.js +110 -0
- data/public/javascripts/kuhsaft/admin/rails.js +157 -0
- data/spec/controllers/admin_assets_controller_spec.rb +26 -0
- data/spec/controllers/admin_pages_controller_spec.rb +33 -0
- data/spec/controllers/pages_controller_spec.rb +18 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +8 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/migrate/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/images/spec-image.png +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories.rb +26 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/kuhsaft_spec.rb +7 -0
- data/spec/models/asset_spec.rb +23 -0
- data/spec/models/localized_page_spec.rb +67 -0
- data/spec/models/page_part_content_spec.rb +22 -0
- data/spec/models/page_part_spec.rb +17 -0
- data/spec/models/page_spec.rb +144 -0
- data/spec/routing/assets_routing_spec.rb +56 -0
- data/spec/routing/pages_routing_spec.rb +79 -0
- data/spec/spec_helper.rb +52 -0
- metadata +390 -9
data/.gitignore
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
spec/dummy/db/*.sqlite3
|
5
|
+
spec/dummy/log/*.log
|
6
|
+
spec/dummy/tmp/
|
7
|
+
spec/dummy/db/migrate/*.rb
|
8
|
+
spec/dummy/db/schema.rb
|
9
|
+
spec/dummy/public/stylesheets/*
|
10
|
+
spec/dummy/public/uploads/tmp/*
|
11
|
+
spec/dummy/public/uploads/kuhsaft/*
|
3
12
|
Gemfile.lock
|
4
|
-
|
13
|
+
.DS_Store
|
14
|
+
.sass-cache
|
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.8.7-p302@kuhsaft"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
17
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
+
else
|
19
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
20
|
+
rvm --create use "$environment_id"
|
21
|
+
fi
|
22
|
+
|
23
|
+
#
|
24
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
25
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
26
|
+
# necessary.
|
27
|
+
#
|
28
|
+
# filename=".gems"
|
29
|
+
# if [[ -s "$filename" ]] ; then
|
30
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
31
|
+
# fi
|
32
|
+
|
33
|
+
#
|
34
|
+
# If you use bundler and would like to run bundle each time you enter the
|
35
|
+
# directory, you can uncomment the following code.
|
36
|
+
#
|
37
|
+
# # Ensure that Bundler is installed. Install it if it is not.
|
38
|
+
# if ! command -v bundle >/dev/null; then
|
39
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
40
|
+
# gem install bundler
|
41
|
+
# fi
|
42
|
+
#
|
43
|
+
# # Bundle while reducing excess noise.
|
44
|
+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
45
|
+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
46
|
+
#
|
47
|
+
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
#
|
4
|
+
guard 'spork' do
|
5
|
+
watch('config/application.rb')
|
6
|
+
watch('config/environment.rb')
|
7
|
+
watch(%r{^config/environments/.*\.rb$})
|
8
|
+
watch(%r{^config/initializers/.*\.rb$})
|
9
|
+
watch('spec/spec_helper.rb')
|
10
|
+
end
|
11
|
+
|
12
|
+
guard 'rspec', :version => 2, :cli => "--drb --colour --fail-fast --format nested" do
|
13
|
+
watch(%r{^spec/.+_spec\.rb})
|
14
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
|
17
|
+
# Rails example
|
18
|
+
watch('spec/spec_helper.rb') { "spec" }
|
19
|
+
watch('config/routes.rb') { "spec/routing" }
|
20
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
21
|
+
watch(%r{^spec/.+_spec\.rb})
|
22
|
+
watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
23
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
24
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
25
|
+
end
|
data/Rakefile
CHANGED
@@ -1,2 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
rescue LoadError
|
7
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
|
13
|
+
require 'rspec/core'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |specs|
|
17
|
+
specs.rspec_opts = %w{--color}
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
21
|
+
|
22
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
|
+
rdoc.rdoc_dir = 'rdoc'
|
24
|
+
rdoc.title = 'Kuhsaft'
|
25
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
26
|
+
rdoc.rdoc_files.include('README.rdoc')
|
27
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Kuhsaft
|
2
|
+
module Admin
|
3
|
+
class AssetsController < ApplicationController
|
4
|
+
respond_to :html
|
5
|
+
layout 'kuhsaft/admin'
|
6
|
+
|
7
|
+
def index
|
8
|
+
@assets = Kuhsaft::Asset.by_date
|
9
|
+
respond_with @assets
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@asset = Kuhsaft::Asset.new
|
14
|
+
respond_with @asset
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
@asset = Kuhsaft::Asset.create params[:kuhsaft_asset]
|
19
|
+
@asset.save
|
20
|
+
respond_with @asset, :location => admin_assets_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
@asset = Kuhsaft::Asset.find(params[:id])
|
25
|
+
respond_with @asset
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@asset = Kuhsaft::Asset.find(params[:id])
|
30
|
+
@asset.update_attributes(params[:kuhsaft_asset])
|
31
|
+
respond_with @asset, :location => admin_assets_path
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
@asset = Kuhsaft::Asset.find(params[:id])
|
36
|
+
@asset.destroy
|
37
|
+
redirect_to admin_assets_path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Kuhsaft
|
2
|
+
module Admin
|
3
|
+
class PagesController < ApplicationController
|
4
|
+
respond_to :html
|
5
|
+
layout 'kuhsaft/admin'
|
6
|
+
before_filter :set_translation_locale
|
7
|
+
helper :all
|
8
|
+
|
9
|
+
def index
|
10
|
+
@pages = Kuhsaft::Page.root_pages
|
11
|
+
respond_with @pages
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@page = Kuhsaft::Page.find(params[:id])
|
16
|
+
respond_with @page
|
17
|
+
end
|
18
|
+
|
19
|
+
def new
|
20
|
+
@page = Kuhsaft::Page.new
|
21
|
+
respond_with @page
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
@page = Kuhsaft::Page.create params[:kuhsaft_page]
|
26
|
+
@page.save
|
27
|
+
respond_with @page, :location => admin_pages_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
@page = Kuhsaft::Page.find(params[:id])
|
32
|
+
respond_with @page
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@page = Kuhsaft::Page.find(params[:id])
|
37
|
+
@page.update_attributes(params[:kuhsaft_page]) if params[:kuhsaft_page].present?
|
38
|
+
# TODO: refactor 'reposition' as a page attribute, so it can be set through update_attributes
|
39
|
+
@page.reposition params[:reposition] if params[:reposition].present? || params.key?(:reposition)
|
40
|
+
respond_with @page, :location => admin_pages_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
@page = Kuhsaft::Page.find(params[:id])
|
45
|
+
@page.destroy
|
46
|
+
redirect_to admin_pages_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_translation_locale
|
50
|
+
Kuhsaft::Page.current_translation_locale = params[:translation_locale] if params[:translation_locale].present?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Kuhsaft::LocalizedPage < ActiveRecord::Base
|
2
|
+
belongs_to :page
|
3
|
+
has_many :page_parts, :class_name => 'Kuhsaft::PagePart::Content'
|
4
|
+
before_validation :create_slug
|
5
|
+
|
6
|
+
validates :title, :presence => true
|
7
|
+
validates :locale, :presence => true
|
8
|
+
validates :slug, :presence => true
|
9
|
+
|
10
|
+
def locale
|
11
|
+
read_attribute(:locale).to_sym unless read_attribute(:locale).nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_slug
|
15
|
+
if title.present? && slug.blank?
|
16
|
+
write_attribute(:slug, read_attribute(:title).downcase.parameterize)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
class Kuhsaft::Page < ActiveRecord::Base
|
2
|
+
has_many :localized_pages
|
3
|
+
has_many :childs, :class_name => 'Kuhsaft::Page', :foreign_key => :parent_id
|
4
|
+
belongs_to :parent, :class_name => 'Kuhsaft::Page', :foreign_key => :parent_id
|
5
|
+
|
6
|
+
scope :root_pages, where('parent_id IS NULL')
|
7
|
+
default_scope order('position ASC')
|
8
|
+
|
9
|
+
delegate :title, :title=,
|
10
|
+
:slug, :slug=,
|
11
|
+
:published, :published=,
|
12
|
+
:keywords, :keywords=,
|
13
|
+
:description, :description=,
|
14
|
+
:locale, :locale=,
|
15
|
+
:body, :body=,
|
16
|
+
:to => :translation
|
17
|
+
|
18
|
+
after_save :save_translation
|
19
|
+
after_create :set_position
|
20
|
+
|
21
|
+
def root?
|
22
|
+
parent.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def localized_page
|
26
|
+
translation
|
27
|
+
end
|
28
|
+
|
29
|
+
def translation
|
30
|
+
unless @localized_page.present?
|
31
|
+
pages = localized_pages.where('locale = ?', Kuhsaft::Page.current_translation_locale)
|
32
|
+
@localized_page = pages.first unless pages.blank?
|
33
|
+
end
|
34
|
+
@localized_page ||= localized_pages.build :locale => Kuhsaft::Page.current_translation_locale
|
35
|
+
end
|
36
|
+
|
37
|
+
def save_translation
|
38
|
+
@localized_page.save unless @localized_page.blank?
|
39
|
+
end
|
40
|
+
|
41
|
+
def increment_position
|
42
|
+
update_attribute :position, position + 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def decrement_position
|
46
|
+
update_attribute :position, position - 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def siblings
|
50
|
+
(parent.present? ? parent.childs : Kuhsaft::Page.root_pages).where('id != ?', id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def preceding_sibling
|
54
|
+
siblings.where('position = ?', position - 1).first
|
55
|
+
end
|
56
|
+
|
57
|
+
def succeeding_sibling
|
58
|
+
siblings.where('position = ?', position + 1).first
|
59
|
+
end
|
60
|
+
|
61
|
+
def preceding_siblings
|
62
|
+
siblings.where('position <= ?', position).where('id != ?', id)
|
63
|
+
end
|
64
|
+
|
65
|
+
def succeeding_siblings
|
66
|
+
siblings.where('position >= ?', position).where('id != ?', id)
|
67
|
+
end
|
68
|
+
|
69
|
+
def position_to_top
|
70
|
+
update_attribute :position, 1
|
71
|
+
recount_siblings_position_from 1
|
72
|
+
end
|
73
|
+
|
74
|
+
def recount_siblings_position_from position
|
75
|
+
counter = position
|
76
|
+
succeeding_siblings.each { |s| counter += 1; s.update_attribute(:position, counter) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def reposition before_id
|
80
|
+
if before_id.blank?
|
81
|
+
position_to_top
|
82
|
+
else
|
83
|
+
update_attribute :position, self.class.position_of(before_id) + 1
|
84
|
+
recount_siblings_position_from position
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_position
|
89
|
+
update_attribute(:position, siblings.count + 1)
|
90
|
+
end
|
91
|
+
|
92
|
+
class << self
|
93
|
+
def position_of id
|
94
|
+
Kuhsaft::Page.find(id).position rescue 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def translation_locales
|
98
|
+
@translation_locales
|
99
|
+
end
|
100
|
+
|
101
|
+
def translation_locales=(array)
|
102
|
+
@translation_locales = array.map(&:to_sym) if array.class == Array
|
103
|
+
end
|
104
|
+
|
105
|
+
def current_translation_locale
|
106
|
+
@translation_locale ||= translation_locales.first
|
107
|
+
end
|
108
|
+
|
109
|
+
def current_translation_locale=(locale)
|
110
|
+
@translation_locale = locale.to_sym
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Kuhsaft
|
2
|
+
module PagePart
|
3
|
+
|
4
|
+
def self.all
|
5
|
+
descendants = []
|
6
|
+
ObjectSpace.each_object(Class) do |k|
|
7
|
+
descendants.unshift k if k < self
|
8
|
+
end
|
9
|
+
descendants.uniq!
|
10
|
+
descendants.map { |d| d.to_s.underscore.to_sym }
|
11
|
+
end
|
12
|
+
|
13
|
+
class Base
|
14
|
+
|
15
|
+
#
|
16
|
+
# TODO: behave like ActiveModel for validations etc
|
17
|
+
# http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
|
18
|
+
#
|
19
|
+
def initialize hash
|
20
|
+
hash.each_pair do |k,v|
|
21
|
+
self.send "#{k}=", v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|