kuhsaft 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +13 -3
  2. data/.rspec +4 -0
  3. data/.rvmrc +47 -0
  4. data/Gemfile +1 -3
  5. data/Guardfile +25 -0
  6. data/Rakefile +28 -2
  7. data/app/controllers/kuhsaft/admin/assets_controller.rb +41 -0
  8. data/app/controllers/kuhsaft/admin/pages_controller.rb +54 -0
  9. data/app/controllers/kuhsaft/pages_controller.rb +11 -0
  10. data/app/models/kuhsaft/asset.rb +4 -0
  11. data/app/models/kuhsaft/localized_page.rb +19 -0
  12. data/app/models/kuhsaft/page.rb +113 -0
  13. data/app/models/kuhsaft/page_part.rb +12 -0
  14. data/app/models/kuhsaft/page_parts/base.rb +26 -0
  15. data/app/models/kuhsaft/page_parts/content.rb +8 -0
  16. data/app/models/kuhsaft/page_parts/markdown.rb +7 -0
  17. data/app/stylesheets/kuhsaft/admin/ie.sass +0 -0
  18. data/app/stylesheets/kuhsaft/admin/partials/_assets.sass +12 -0
  19. data/app/stylesheets/kuhsaft/admin/partials/_buttons.sass +216 -0
  20. data/app/stylesheets/kuhsaft/admin/partials/_generic.sass +29 -0
  21. data/app/stylesheets/kuhsaft/admin/partials/_pages.sass +38 -0
  22. data/app/stylesheets/kuhsaft/admin/print.sass +0 -0
  23. data/app/stylesheets/kuhsaft/admin/screen.sass +8 -0
  24. data/app/uploaders/kuhsaft/asset_uploader.rb +47 -0
  25. data/app/views/kuhsaft/admin/assets/_form.html.haml +3 -0
  26. data/app/views/kuhsaft/admin/assets/_list.html.haml +7 -0
  27. data/app/views/kuhsaft/admin/assets/edit.html.haml +1 -0
  28. data/app/views/kuhsaft/admin/assets/index.html.haml +3 -0
  29. data/app/views/kuhsaft/admin/assets/new.html.haml +1 -0
  30. data/app/views/kuhsaft/admin/pages/_branch.html.haml +10 -0
  31. data/app/views/kuhsaft/admin/pages/_form.html.haml +11 -0
  32. data/app/views/kuhsaft/admin/pages/edit.html.haml +1 -0
  33. data/app/views/kuhsaft/admin/pages/index.html.haml +17 -0
  34. data/app/views/kuhsaft/admin/pages/new.html.haml +1 -0
  35. data/app/views/kuhsaft/admin/pages/show.html.haml +0 -0
  36. data/app/views/kuhsaft/pages/index.html.haml +0 -0
  37. data/app/views/kuhsaft/pages/show.html.haml +0 -0
  38. data/app/views/layouts/kuhsaft/admin.html.haml +21 -0
  39. data/config/initializers/compass.rb +3 -0
  40. data/config/initializers/generators.rb +7 -0
  41. data/config/locales/kuhsaft.en.yml +20 -0
  42. data/config/routes.rb +9 -0
  43. data/db/migrate/20110302101530_create_kuhsaft_pages.rb +14 -0
  44. data/db/migrate/20110302113020_create_kuhsaft_localized_pages.rb +19 -0
  45. data/db/migrate/20110302125123_create_page_part_contents.rb +14 -0
  46. data/db/migrate/20110307162621_create_assets.rb +12 -0
  47. data/kuhsaft.gemspec +19 -2
  48. data/lib/kuhsaft.rb +3 -1
  49. data/lib/kuhsaft/engine.rb +19 -0
  50. data/lib/kuhsaft/version.rb +1 -1
  51. data/public/images/css3buttons_backgrounds.png +0 -0
  52. data/public/images/css3buttons_icons.png +0 -0
  53. data/public/images/drag-handle.png +0 -0
  54. data/public/javascripts/kuhsaft/admin/jquery-1.4.4.js +7179 -0
  55. data/public/javascripts/kuhsaft/admin/jquery-ui-1.8.10.custom.min.js +110 -0
  56. data/public/javascripts/kuhsaft/admin/rails.js +157 -0
  57. data/spec/controllers/admin_assets_controller_spec.rb +26 -0
  58. data/spec/controllers/admin_pages_controller_spec.rb +33 -0
  59. data/spec/controllers/pages_controller_spec.rb +18 -0
  60. data/spec/dummy/Rakefile +7 -0
  61. data/spec/dummy/app/controllers/application_controller.rb +8 -0
  62. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  63. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/config/application.rb +45 -0
  66. data/spec/dummy/config/boot.rb +10 -0
  67. data/spec/dummy/config/database.yml +22 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/config/environments/development.rb +26 -0
  70. data/spec/dummy/config/environments/production.rb +49 -0
  71. data/spec/dummy/config/environments/test.rb +35 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/dummy/config/initializers/inflections.rb +10 -0
  74. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  75. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  76. data/spec/dummy/config/initializers/session_store.rb +8 -0
  77. data/spec/dummy/config/locales/en.yml +5 -0
  78. data/spec/dummy/config/routes.rb +58 -0
  79. data/spec/dummy/db/migrate/.gitkeep +0 -0
  80. data/spec/dummy/public/404.html +26 -0
  81. data/spec/dummy/public/422.html +26 -0
  82. data/spec/dummy/public/500.html +26 -0
  83. data/spec/dummy/public/favicon.ico +0 -0
  84. data/spec/dummy/public/images/spec-image.png +0 -0
  85. data/spec/dummy/script/rails +6 -0
  86. data/spec/factories.rb +26 -0
  87. data/spec/integration/navigation_spec.rb +9 -0
  88. data/spec/kuhsaft_spec.rb +7 -0
  89. data/spec/models/asset_spec.rb +23 -0
  90. data/spec/models/localized_page_spec.rb +67 -0
  91. data/spec/models/page_part_content_spec.rb +22 -0
  92. data/spec/models/page_part_spec.rb +17 -0
  93. data/spec/models/page_spec.rb +144 -0
  94. data/spec/routing/assets_routing_spec.rb +56 -0
  95. data/spec/routing/pages_routing_spec.rb +79 -0
  96. data/spec/spec_helper.rb +52 -0
  97. metadata +390 -9
data/.gitignore CHANGED
@@ -1,4 +1,14 @@
1
- *.gem
2
- .bundle
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
- pkg/*
13
+ .DS_Store
14
+ .sass-cache
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --fail-fast
3
+ --drb
4
+ --format nested
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
@@ -1,4 +1,2 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in kuhsaft.gemspec
1
+ source 'http://rubygems.org'
4
2
  gemspec
@@ -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
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
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,11 @@
1
+ module Kuhsaft
2
+ class PagesController < ApplicationController
3
+
4
+ respond_to :html
5
+
6
+ def show
7
+ @page = Kuhsaft::LocalizedPage.where('slug = ?', params[:slug]).where('locale = ?', params[:translation_locale]).first
8
+ respond_with @page
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ class Kuhsaft::Asset < ActiveRecord::Base
2
+ scope :by_date, order('updated_at DESC')
3
+ mount_uploader :file, Kuhsaft::AssetUploader
4
+ 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,12 @@
1
+ module Kuhsaft
2
+ module PagePart
3
+ def self.all
4
+ descendants = []
5
+ ObjectSpace.each_object(Class) do |k|
6
+ descendants.unshift k if k < self
7
+ end
8
+ descendants.uniq!
9
+ descendants.map { |d| d.to_s.underscore.to_sym }
10
+ end
11
+ end
12
+ 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
@@ -0,0 +1,8 @@
1
+ module Kuhsaft
2
+ module PagePart
3
+ class Content < ActiveRecord::Base
4
+ belongs_to :localized_page
5
+ serialize :content
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Kuhsaft
2
+ module PagePart
3
+ class Markdown < PagePart::Base
4
+ attr_accessor :text
5
+ end
6
+ end
7
+ end