humpyard 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +28 -0
- data/README.rdoc +61 -0
- data/VERSION +1 -0
- data/app/controllers/humpyard/assets_controller.rb +123 -0
- data/app/controllers/humpyard/elements_controller.rb +200 -0
- data/app/controllers/humpyard/errors_controller.rb +8 -0
- data/app/controllers/humpyard/pages_controller.rb +365 -0
- data/app/helpers/humpyard/pages_helper.rb +19 -0
- data/app/models/humpyard/asset.rb +22 -0
- data/app/models/humpyard/assets/paperclip_asset.rb +48 -0
- data/app/models/humpyard/assets/youtube_asset.rb +38 -0
- data/app/models/humpyard/element.rb +57 -0
- data/app/models/humpyard/elements/box_element.rb +15 -0
- data/app/models/humpyard/elements/media_element.rb +13 -0
- data/app/models/humpyard/elements/news_element.rb +13 -0
- data/app/models/humpyard/elements/sitemap_element.rb +11 -0
- data/app/models/humpyard/elements/text_element.rb +49 -0
- data/app/models/humpyard/news_item.rb +42 -0
- data/app/models/humpyard/page.rb +153 -0
- data/app/models/humpyard/pages/news_page.rb +71 -0
- data/app/models/humpyard/pages/static_page.rb +25 -0
- data/app/models/humpyard/pages/virtual_page.rb +30 -0
- data/app/views/humpyard/assets/_edit.html.haml +15 -0
- data/app/views/humpyard/assets/_index.html.haml +24 -0
- data/app/views/humpyard/assets/_list.html.haml +4 -0
- data/app/views/humpyard/assets/_list_item.html.haml +1 -0
- data/app/views/humpyard/assets/_show.html.haml +38 -0
- data/app/views/humpyard/assets/_show_asset.html.haml +3 -0
- data/app/views/humpyard/assets/destroy.js.erb +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_info_table.html.haml +10 -0
- data/app/views/humpyard/assets/paperclip_assets/_show.html.haml +12 -0
- data/app/views/humpyard/assets/youtube_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/youtube_assets/_show.html.haml +5 -0
- data/app/views/humpyard/common/_head.html.haml +8 -0
- data/app/views/humpyard/common/_page_construct.html.haml +45 -0
- data/app/views/humpyard/elements/_edit.html.haml +25 -0
- data/app/views/humpyard/elements/_inline_edit.haml +0 -0
- data/app/views/humpyard/elements/_new.html.haml +1 -0
- data/app/views/humpyard/elements/_show.html.haml +29 -0
- data/app/views/humpyard/elements/_show_container.html.haml +3 -0
- data/app/views/humpyard/elements/_show_view.html.haml +2 -0
- data/app/views/humpyard/elements/box_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/box_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/box_elements/_show.html.haml +5 -0
- data/app/views/humpyard/elements/destroy.js.erb +1 -0
- data/app/views/humpyard/elements/error.js.erb +1 -0
- data/app/views/humpyard/elements/media_elements/_edit.html.haml +7 -0
- data/app/views/humpyard/elements/media_elements/_show.html.haml +8 -0
- data/app/views/humpyard/elements/news_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/news_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/news_elements/_show.html.haml +4 -0
- data/app/views/humpyard/elements/sitemap_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/sitemap_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/sitemap_elements/_show.html.haml +3 -0
- data/app/views/humpyard/elements/sitemap_elements/_show_part.html.haml +12 -0
- data/app/views/humpyard/elements/text_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/text_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/text_elements/_show.html.haml +4 -0
- data/app/views/humpyard/pages/_content.html.haml +2 -0
- data/app/views/humpyard/pages/_edit.html.haml +39 -0
- data/app/views/humpyard/pages/_index.html.haml +23 -0
- data/app/views/humpyard/pages/_show.html.haml +16 -0
- data/app/views/humpyard/pages/_subtree.html.haml +6 -0
- data/app/views/humpyard/pages/_tree.html.haml +3 -0
- data/app/views/humpyard/pages/destroy.js.erb +4 -0
- data/app/views/humpyard/pages/news_pages/_detail.html.haml +10 -0
- data/app/views/humpyard/pages/news_pages/_edit.html.haml +3 -0
- data/app/views/humpyard/pages/news_pages/_show.html.haml +5 -0
- data/app/views/humpyard/pages/show.html.haml +3 -0
- data/app/views/humpyard/pages/static_pages/_edit.html.haml +1 -0
- data/app/views/humpyard/pages/static_pages/_show.html.haml +1 -0
- data/app/views/humpyard/pages/virtual_pages/_edit.html.haml +7 -0
- data/app/views/humpyard/pages/virtual_pages/_show.html.haml +4 -0
- data/app/views/humpyard/pages/welcome.html.haml +13 -0
- data/compass/stylesheets/_humpyard.scss +12 -0
- data/compass/stylesheets/humpyard/_backend.scss +1 -0
- data/compass/stylesheets/humpyard/_base.scss +144 -0
- data/compass/stylesheets/humpyard/_ie.scss +1 -0
- data/compass/stylesheets/humpyard/_jquery_ui_overrides.scss +380 -0
- data/compass/stylesheets/humpyard/_print.scss +3 -0
- data/config/locales/de.yml +84 -0
- data/config/locales/en.yml +81 -0
- data/config/routes.rb +38 -0
- data/db/migrate/20100321134138_base.rb +60 -0
- data/db/migrate/20100330204700_create_box_element.rb +24 -0
- data/db/migrate/20100401153655_page_template.rb +11 -0
- data/db/migrate/20100409195732_page_types.rb +26 -0
- data/db/migrate/20100413230623_element_yield.rb +14 -0
- data/db/migrate/20100415132312_news_page.rb +48 -0
- data/db/migrate/20100415193423_page_i18n_name.rb +27 -0
- data/db/migrate/20100415213700_create_news_element.rb +12 -0
- data/db/migrate/20100703120000_shared_elements.rb +9 -0
- data/db/migrate/20101001142534_page_modified_at.rb +11 -0
- data/db/migrate/20101003100138_create_sitemap_elements.rb +13 -0
- data/db/migrate/20101003122108_create_humpyard_pages_virtual_pages.rb +11 -0
- data/db/migrate/20101006070503_page_cache_control.rb +9 -0
- data/db/migrate/20101104173743_create_media.rb +36 -0
- data/db/migrate/20110425230524_media_with_link.rb +9 -0
- data/lib/generators/humpyard.rb +114 -0
- data/lib/generators/humpyard/auth/auth_generator.rb +191 -0
- data/lib/generators/humpyard/auth/templates/authlogic/README +9 -0
- data/lib/generators/humpyard/auth/templates/authlogic/controllers/user_sessions_controller.rb +22 -0
- data/lib/generators/humpyard/auth/templates/authlogic/migration.rb +17 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user.rb +7 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user_session.rb +6 -0
- data/lib/generators/humpyard/auth/templates/authlogic/views/user_sessions/new.html.haml +12 -0
- data/lib/generators/humpyard/auth/templates/custom/README +8 -0
- data/lib/generators/humpyard/auth/templates/devise/README +14 -0
- data/lib/generators/humpyard/auth/templates/devise/models/ability.rb +14 -0
- data/lib/generators/humpyard/auth/templates/fake/README +0 -0
- data/lib/generators/humpyard/auth/templates/fake/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/README +16 -0
- data/lib/generators/humpyard/auth/templates/simple/config/humpyard_users.yml +2 -0
- data/lib/generators/humpyard/auth/templates/simple/controllers/user_sessions_controller.rb +39 -0
- data/lib/generators/humpyard/auth/templates/simple/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/views/user_sessions/new.html.haml +15 -0
- data/lib/generators/humpyard/element/USAGE +7 -0
- data/lib/generators/humpyard/element/element_generator.rb +82 -0
- data/lib/generators/humpyard/element/templates/_edit.html.haml +12 -0
- data/lib/generators/humpyard/element/templates/_inline_edit.html.haml +0 -0
- data/lib/generators/humpyard/element/templates/_show.html.haml +9 -0
- data/lib/generators/humpyard/element/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/element/templates/migration.rb +16 -0
- data/lib/generators/humpyard/element/templates/model.rb +11 -0
- data/lib/generators/humpyard/element/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/page/USAGE +7 -0
- data/lib/generators/humpyard/page/page_generator.rb +80 -0
- data/lib/generators/humpyard/page/templates/_edit.html.haml +7 -0
- data/lib/generators/humpyard/page/templates/_show.html.haml +4 -0
- data/lib/generators/humpyard/page/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/page/templates/migration.rb +16 -0
- data/lib/generators/humpyard/page/templates/model.rb +37 -0
- data/lib/generators/humpyard/page/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/skeleton/USAGE +6 -0
- data/lib/generators/humpyard/skeleton/skeleton_generator.rb +99 -0
- data/lib/generators/humpyard/skeleton/templates/compass.config +14 -0
- data/lib/generators/humpyard/skeleton/templates/images/ajax-loader.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/images/grid.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/compass.rb +16 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/haml.rb +3 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/humpyard.rb +20 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/d.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/throbber.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-1.5.1.js +8316 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-humpyard.js +790 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-rails.js +157 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-ui-1.8.10.js +11544 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.form-2.64.js +803 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.jstree.js +3510 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/jquery-ui-1.8.10.css +573 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.sass +15 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.scss +16 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.sass +12 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.scss +11 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.sass +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.scss +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.sass +78 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.scss +90 -0
- data/lib/generators/humpyard/skeleton/templates/views/layout.html.haml +28 -0
- data/lib/html_to_textile.rb +220 -0
- data/lib/humpyard.rb +70 -0
- data/lib/humpyard/action_controller/base.rb +24 -0
- data/lib/humpyard/active_model/naming.rb +29 -0
- data/lib/humpyard/active_model/translation.rb +26 -0
- data/lib/humpyard/active_model/validators/publish_range.rb +14 -0
- data/lib/humpyard/active_record/acts/asset.rb +68 -0
- data/lib/humpyard/active_record/acts/container_element.rb +26 -0
- data/lib/humpyard/active_record/acts/element.rb +89 -0
- data/lib/humpyard/active_record/acts/page.rb +101 -0
- data/lib/humpyard/active_record/has/title_for_url.rb +75 -0
- data/lib/humpyard/compass.rb +6 -0
- data/lib/humpyard/config.rb +235 -0
- data/lib/humpyard/engine.rb +7 -0
- data/lib/humpyard/uri_parser.rb +16 -0
- data/lib/humpyard/uri_parser/assets_uri_parser.rb +15 -0
- data/lib/humpyard/uri_parser/pages_uri_parser.rb +15 -0
- data/lib/tasks/humpyard.rake +103 -0
- metadata +331 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
class PageModifiedAt < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :pages, :modified_at, :datetime, :after => :updated_at
|
4
|
+
add_column :pages, :refresh_scheduled_at, :datetime, :after => :modified_at
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :pages, :modified_at
|
9
|
+
remove_column :pages, :refresh_scheduled_at
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSitemapElements < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :elements_sitemap_elements do |t|
|
4
|
+
t.integer :levels
|
5
|
+
t.boolean :show_description
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :elements_sitemap_elements
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class CreateMedia < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :assets do |t|
|
4
|
+
t.string :title
|
5
|
+
t.integer :width
|
6
|
+
t.integer :height
|
7
|
+
t.references :content_data
|
8
|
+
t.string :content_data_type
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :assets_paperclip_assets do |t|
|
13
|
+
t.string :media_file_name
|
14
|
+
t.integer :media_file_size
|
15
|
+
t.string :media_content_type
|
16
|
+
t.datetime :media_updated_at
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table :assets_youtube_assets do |t|
|
21
|
+
t.string :youtube_video_id
|
22
|
+
t.string :youtube_title
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :elements_media_elements do |t|
|
27
|
+
t.references :asset
|
28
|
+
t.string :float
|
29
|
+
t.timestamps
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.down
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Humpyard
|
4
|
+
####
|
5
|
+
# = Humpyard::Generators
|
6
|
+
#
|
7
|
+
module Generators
|
8
|
+
class Base < Rails::Generators::Base #:nodoc:
|
9
|
+
def self.source_root
|
10
|
+
@_humpyard_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'humpyard', generator_name, 'templates'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"#{$0} humpyard:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ModelTemplate
|
19
|
+
|
20
|
+
def self.included(base) #:nodoc:
|
21
|
+
base.extend ClassMethods
|
22
|
+
|
23
|
+
base.argument :model_attributes, :type => :array, :default => [], :banner => 'field:type field:type'
|
24
|
+
|
25
|
+
base.class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
26
|
+
base.class_option :skip_migration, :desc => 'Dont generate migration file for model.', :type => :boolean
|
27
|
+
base.class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
|
28
|
+
base.class_option :skip_views, :desc => 'Don\'t generate view files.', :type => :boolean
|
29
|
+
|
30
|
+
base.class_option :skip_tests, :desc => 'Don\'t generate test files.', :group => 'Test framework', :type => :boolean
|
31
|
+
base.class_option :test_unit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
|
32
|
+
base.class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
33
|
+
base.class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def create_model options # :nodoc:
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def attributes
|
43
|
+
if @attributes
|
44
|
+
return @attributes
|
45
|
+
else
|
46
|
+
@attributes = []
|
47
|
+
model_attributes.each do |attr|
|
48
|
+
splitted = attr.split(':')
|
49
|
+
@attributes << Rails::Generators::GeneratedAttribute.new(splitted[0], splitted[1])
|
50
|
+
end
|
51
|
+
@attributes
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def model_name
|
56
|
+
raise "You have to specify model name in your Generator"
|
57
|
+
end
|
58
|
+
|
59
|
+
def singular_name
|
60
|
+
model_name.underscore
|
61
|
+
end
|
62
|
+
|
63
|
+
def plural_name
|
64
|
+
model_name.underscore.pluralize
|
65
|
+
end
|
66
|
+
|
67
|
+
def class_name
|
68
|
+
model_name.camelize
|
69
|
+
end
|
70
|
+
|
71
|
+
def plural_class_name
|
72
|
+
plural_name.camelize
|
73
|
+
end
|
74
|
+
|
75
|
+
def model_exists?
|
76
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_framework
|
80
|
+
return @test_framework if defined?(@test_framework)
|
81
|
+
|
82
|
+
if options.rspec?
|
83
|
+
return @test_framework = :rspec
|
84
|
+
elsif options.test_unit?
|
85
|
+
return @test_framework = :test_unit
|
86
|
+
elsif options.shoulda?
|
87
|
+
return @test_framework = :shoulda
|
88
|
+
else
|
89
|
+
return @test_framework = default_test_framework
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def default_test_framework
|
94
|
+
Rails.application::config.generators.rails[:test_framework]
|
95
|
+
end
|
96
|
+
|
97
|
+
def destination_path(path)
|
98
|
+
File.join(destination_root, path)
|
99
|
+
end
|
100
|
+
|
101
|
+
module ClassMethods
|
102
|
+
# Implement the required interface for Rails::Generators::Migration.
|
103
|
+
#
|
104
|
+
def next_migration_number(dirname) #:nodoc:
|
105
|
+
if ::ActiveRecord::Base.timestamped_migrations
|
106
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
107
|
+
else
|
108
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'generators/humpyard'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
require 'rails/generators/active_model'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
module Humpyard
|
8
|
+
module Generators
|
9
|
+
####
|
10
|
+
# == User Generator
|
11
|
+
#
|
12
|
+
# rails humpyard:auth user_model [options]
|
13
|
+
#
|
14
|
+
# === Description
|
15
|
+
# The humpyard user generator creates a basic auth
|
16
|
+
#
|
17
|
+
# === Options
|
18
|
+
#
|
19
|
+
# === Runtime options
|
20
|
+
# <tt>-q, [--quiet]</tt>:: Supress status output
|
21
|
+
# <tt>-p, [--pretend]</tt>:: Run but do not make any changes
|
22
|
+
# <tt>-s, [--skip]</tt>:: Skip files that already exist
|
23
|
+
# <tt>-f, [--force]</tt>:: Overwrite files that already exist
|
24
|
+
#
|
25
|
+
# === Examples
|
26
|
+
# rails generate humpyard:auth user
|
27
|
+
|
28
|
+
class AuthGenerator < Base
|
29
|
+
include Rails::Generators::Migration
|
30
|
+
|
31
|
+
argument :user_model, :type => :string, :required => true, :banner => 'UserModel'
|
32
|
+
|
33
|
+
include Humpyard::Generators::ModelTemplate
|
34
|
+
|
35
|
+
class_option :users_framework, :desc => 'The user management framework used in humpyard application (options: simple/custom/fake/devise/authlogic)', :group => 'Users config', :type => :string, :default => Humpyard::config.users_framework
|
36
|
+
class_option :skip_models, :desc => 'Don\'t generate User realated models', :type => :boolean
|
37
|
+
class_option :skip_haml, :desc => 'Don\'t generate HAML related files (the layout template)', :type => :boolean
|
38
|
+
class_option :skip_injection, :desc => 'Don\'t inject anything to files like routes.rb or application_controller.rb', :type => :boolean
|
39
|
+
|
40
|
+
def create_user # :nodoc:
|
41
|
+
template_path = "#{::File.dirname(__FILE__)}/templates/"
|
42
|
+
|
43
|
+
#Dir.glob("#{template_path}#{options[:users_framework]}/**/*.*").each do |file|
|
44
|
+
# template file.gsub(template_path, ''), "app/#{file.gsub("#{template_path}#{options[:users_framework]}/", '')}"
|
45
|
+
#end
|
46
|
+
|
47
|
+
application_controller_injection =
|
48
|
+
" helper_method :current_user\n\n" +
|
49
|
+
" # Handle AccessDenied exception of CanCan\n" +
|
50
|
+
" rescue_from CanCan::AccessDenied do |exception|\n" +
|
51
|
+
" flash[:error] = exception.message\n" +
|
52
|
+
" redirect_to root_url\n" +
|
53
|
+
" end\n\n"
|
54
|
+
|
55
|
+
routes_injection = ""
|
56
|
+
|
57
|
+
class_collisions class_name
|
58
|
+
|
59
|
+
template "#{options[:users_framework]}/models/ability.rb", "app/models/ability.rb"
|
60
|
+
|
61
|
+
case options[:users_framework]
|
62
|
+
when 'simple'
|
63
|
+
template "simple/controllers/user_sessions_controller.rb", "app/controllers/#{singular_name}_sessions_controller.rb"
|
64
|
+
template "simple/config/humpyard_users.yml", "config/humpyard_#{plural_name}.yml"
|
65
|
+
template "simple/views/user_sessions/new.html.haml", "app/views/#{singular_name}_sessions/new.html.haml"
|
66
|
+
|
67
|
+
application_controller_injection +=
|
68
|
+
" private\n" +
|
69
|
+
" def current_user\n" +
|
70
|
+
" if not @current_user.nil?\n" +
|
71
|
+
" @current_user\n" +
|
72
|
+
" else\n" +
|
73
|
+
" session[:humpyard] ||= {}\n" +
|
74
|
+
" @current_user = session[:humpyard][:user] || false\n" +
|
75
|
+
" end\n" +
|
76
|
+
" end\n" +
|
77
|
+
"\n" +
|
78
|
+
" private\n" +
|
79
|
+
" def humpyard_logout_path\n" +
|
80
|
+
" logout_path\n" +
|
81
|
+
" end\n\n"
|
82
|
+
|
83
|
+
routes_injection += "scope \"/#"+"{Humpyard::config.admin_prefix}\" do\n" +
|
84
|
+
" get 'login' => '#{singular_name}_sessions#new', :as => :login\n" +
|
85
|
+
" post 'login' => '#{singular_name}_sessions#create', :as => :login\n" +
|
86
|
+
" get 'logout' => '#{singular_name}_sessions#destroy', :as => :logout\n" +
|
87
|
+
" end"
|
88
|
+
when 'authlogic'
|
89
|
+
|
90
|
+
raise "Authlogic is not working, yet!"
|
91
|
+
|
92
|
+
template "authlogic/models/ability.rb", "app/models/ability.rb"
|
93
|
+
template "authlogic/models/user.rb", "app/models/#{singular_name}.rb"
|
94
|
+
template "authlogic/models/user_session.rb", "app/models/#{singular_name}_session.rb"
|
95
|
+
|
96
|
+
unless true or options.skip_tests?
|
97
|
+
case test_framework
|
98
|
+
when :rspec
|
99
|
+
template "authlogic/tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb"
|
100
|
+
template "authlogic/fixtures.yml", "spec/fixtures/#{plural_name}.yml"
|
101
|
+
else
|
102
|
+
template "authlogic/tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
|
103
|
+
template "authlogic/fixtures.yml", "test/fixtures/#{plural_name}.yml"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
unless options.skip_migration?
|
108
|
+
migration_template 'authlogic/migration.rb', "db/migrate/create_#{plural_name.gsub('/','_')}.rb"
|
109
|
+
end
|
110
|
+
|
111
|
+
template "authlogic/controllers/user_sessions_controller.rb", "app/controllers/#{singular_name}_sessions_controller.rb"
|
112
|
+
|
113
|
+
routes_injection += "resources :#{singular_name}_sessions"
|
114
|
+
|
115
|
+
unless options.skip_views?
|
116
|
+
template 'authlogic/views/user_sessions/new.html.haml', "app/views/#{singular_name}_sessions/new.html.haml"
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
gem 'authlogic', :git => 'http://github.com/odorcicd/authlogic.git', :branch => 'rails3'
|
121
|
+
|
122
|
+
|
123
|
+
application_controller_injection +=
|
124
|
+
" private\n" +
|
125
|
+
" def current_user_session\n" +
|
126
|
+
" return @current_user_session if defined?(@current_user_session)\n" +
|
127
|
+
" @current_user_session = UserSession.find\n" +
|
128
|
+
" end\n\n" +
|
129
|
+
" def current_user\n" +
|
130
|
+
" return @current_user if defined?(@current_user)\n" +
|
131
|
+
" @current_user = current_user_session && current_user_session.record\n" +
|
132
|
+
" end\n"
|
133
|
+
when 'devise'
|
134
|
+
|
135
|
+
raise "Devise is not working, yet!"
|
136
|
+
|
137
|
+
template "#{options[:users_framework]}/models/ability.rb", "app/models/ability.rb"
|
138
|
+
gem 'devise', :git => 'http://github.com/plataformatec/devise.git' #,'>= 1.1.rc1'
|
139
|
+
|
140
|
+
run "bundle install"
|
141
|
+
|
142
|
+
generate :devise_install
|
143
|
+
|
144
|
+
prepend_file "config/initializers/devise.rb", "require 'devise'\n\n"
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
generate :devise, singular_name
|
149
|
+
|
150
|
+
when 'fake'
|
151
|
+
application_controller_injection +=
|
152
|
+
" private\n" +
|
153
|
+
" def current_user\n" +
|
154
|
+
" if not @current_user.nil?\n" +
|
155
|
+
" @current_user\n" +
|
156
|
+
" else\n" +
|
157
|
+
" session[:humpyard] ||= {}\n" +
|
158
|
+
" unless params[:user].nil?\n" +
|
159
|
+
" session[:humpyard][:user] = params[:user].blank? ? false : params[:user]\n" +
|
160
|
+
" end\n" +
|
161
|
+
" @current_user = session[:humpyard][:user] || false\n" +
|
162
|
+
" end\n" +
|
163
|
+
" end\n"
|
164
|
+
end
|
165
|
+
|
166
|
+
unless options.skip_injection
|
167
|
+
route routes_injection unless routes_injection.blank?
|
168
|
+
inject_into_class "app/controllers/application_controller.rb", ApplicationController, application_controller_injection
|
169
|
+
end
|
170
|
+
|
171
|
+
begin
|
172
|
+
File.open("#{template_path}#{options[:users_framework]}/README", "r") do |infile|
|
173
|
+
puts ''
|
174
|
+
while (line = infile.gets)
|
175
|
+
puts " #{line}"
|
176
|
+
end
|
177
|
+
puts ''
|
178
|
+
end
|
179
|
+
rescue
|
180
|
+
# No README found, do nothing
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
def model_name
|
186
|
+
"#{user_model.camelize}"
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class <%= class_name %>SessionsController < ApplicationController
|
2
|
+
def new
|
3
|
+
@user_session = <%= class_name %>Session.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def create
|
7
|
+
@user_session = <%= class_name %>Session.new(params[:user_session])
|
8
|
+
if @user_session.save
|
9
|
+
flash[:notice] = "Successfully logged in."
|
10
|
+
redirect_to root_url
|
11
|
+
else
|
12
|
+
render :action => :new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
@user_session = <%= class_name %>Session.find
|
18
|
+
@user_session.destroy
|
19
|
+
flash[:notice] = "Successfully logged out."
|
20
|
+
redirect_to root_url
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
t.string :username
|
5
|
+
t.string :email
|
6
|
+
t.boolean :admin, :default => false
|
7
|
+
t.string :crypted_password
|
8
|
+
t.string :password_salt
|
9
|
+
t.string :persistence_token
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :users
|
16
|
+
end
|
17
|
+
end
|