wheels 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/VERSION +1 -1
  2. data/app/controllers/blogs_controller.rb +7 -6
  3. data/app/controllers/galleries_controller.rb +3 -3
  4. data/app/controllers/pages_controller.rb +11 -0
  5. data/app/controllers/profiles_controller.rb +1 -1
  6. data/app/helpers/blogs_helper.rb +10 -0
  7. data/app/helpers/pages_helper.rb +11 -0
  8. data/app/models/ability.rb +20 -3
  9. data/app/models/blog.rb +2 -1
  10. data/app/models/image.rb +3 -1
  11. data/app/models/page.rb +5 -0
  12. data/app/models/page_revision.rb +2 -0
  13. data/app/models/profile.rb +1 -0
  14. data/app/models/tagging.rb +4 -0
  15. data/app/models/user.rb +17 -12
  16. data/app/views/blogs/_form.html.haml +4 -10
  17. data/app/views/blogs/index.html.haml +4 -0
  18. data/app/views/blogs/show.html.haml +3 -4
  19. data/app/views/galleries/_form.html.haml +3 -2
  20. data/app/views/galleries/_show.html.haml +2 -2
  21. data/app/views/galleries/show.html.haml +2 -2
  22. data/app/views/layouts/application.html.haml +48 -0
  23. data/app/views/pages/_form.html.haml +19 -0
  24. data/app/views/pages/edit.html.haml +7 -0
  25. data/app/views/pages/index.html.haml +21 -0
  26. data/app/views/pages/new.html.haml +5 -0
  27. data/app/views/pages/show.html.haml +6 -0
  28. data/db/migrate/create_blogs.rb +1 -1
  29. data/db/migrate/create_roles.rb +0 -3
  30. data/db/migrate/insert_admin_user_and_roles.rb +4 -4
  31. data/lib/generators/app_layout/LICENCE +20 -0
  32. data/lib/generators/app_layout/USAGE +8 -0
  33. data/lib/generators/app_layout/app_layout_generator.rb +18 -0
  34. data/lib/generators/app_layout/core_extensions.rb +51 -0
  35. data/lib/generators/update_wheels/LICENCE +20 -0
  36. data/lib/generators/update_wheels/USAGE +8 -0
  37. data/lib/generators/update_wheels/core_extensions.rb +51 -0
  38. data/lib/generators/update_wheels/recipes/wheels.rb +11 -0
  39. data/lib/generators/update_wheels/templates/cancan/ability.rb +13 -0
  40. data/lib/generators/update_wheels/templates/database/postgresql.yml +19 -0
  41. data/lib/generators/update_wheels/templates/git/gitignore +8 -0
  42. data/lib/generators/update_wheels/templates/haml/app/views/layouts/application.html.haml +9 -0
  43. data/lib/generators/update_wheels/templates/mongoid/features/step_definitions/mongoid_steps.rb +4 -0
  44. data/lib/generators/update_wheels/templates/mongoid/features/support/hooks.rb +3 -0
  45. data/lib/generators/update_wheels/update_wheels_generator.rb +43 -0
  46. data/lib/generators/wheels/recipes/cancan.rb +3 -3
  47. data/lib/generators/wheels/recipes/haml.rb +2 -2
  48. data/lib/generators/wheels/recipes/recipes.rb +164 -0
  49. data/lib/generators/wheels/recipes/wheels.rb +41 -35
  50. data/lib/generators/wheels/templates/haml/app/views/layouts/application.html.haml +0 -9
  51. data/lib/generators/wheels/views_generator.rb +15 -0
  52. data/lib/generators/wheels/wheels_generator.rb +1 -1
  53. data/lib/generators/wheels_views/LICENCE +20 -0
  54. data/lib/generators/wheels_views/USAGE +8 -0
  55. data/lib/generators/wheels_views/wheels_views_generator.rb +15 -0
  56. data/lib/wheels/action_view_helper_extensions.rb +9 -0
  57. data/lib/wheels/active_record_extensions.rb +44 -0
  58. data/lib/wheels/active_record_user_extensions.rb +34 -0
  59. data/lib/wheels/user.rb +32 -0
  60. data/lib/wheels/wheels_engine.rb +7 -0
  61. data/lib/wheels.rb +2 -0
  62. data/public/javascripts/galleries/configure_ckeditor.js +8 -0
  63. data/public/javascripts/jqUrl.js +28 -0
  64. data/public/stylesheets/dreamy.css +3 -1
  65. data/public/stylesheets/sass/dreamy.sass +3 -0
  66. data/public/stylesheets/sass/wheels.sass +25 -0
  67. data/wheels.gemspec +42 -2
  68. metadata +44 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.18
@@ -1,17 +1,18 @@
1
1
  class BlogsController < InheritedResources::Base
2
2
  respond_to :html, :xml
3
- belongs_to :user, :optional=>true
4
- before_filter :load_current_user
3
+ before_filter
4
+ has_scope :tagged_with, :as => :tag
5
+ belongs_to :user, :optional => true
5
6
 
6
7
  def collection
7
8
  @blogs ||= end_of_association_chain.
8
9
  paginate(:page => params[:page], :order => 'created_at DESC' )
9
10
  end
10
11
 
11
- def load_current_user
12
- unless params[:user_id]
13
- @user ||= (current_user ? User.find(current_user.id) : User.super_user)
14
- end
12
+ def begin_of_association_chain
13
+ @user ||= (current_user ? User.find(current_user.id) : super_user)
14
+ @tags = Blog.where(:user_id=>@user.id).tag_counts.sort{|t, u| t.count <=> u.count}
15
+ return @user
15
16
  end
16
17
  end
17
18
 
@@ -24,10 +24,10 @@ class GalleriesController < InheritedResources::Base
24
24
 
25
25
  def show
26
26
  show! do |format|
27
- images = paginated_images_for(@gallery)
27
+ @images = paginated_images_for(@gallery)
28
28
  if params[:CKEditorFuncNum]
29
29
  format.html{
30
- render :action=>:show, :layout=>"image_dialog", :locals=>{:images=>images}
30
+ render :action=>:show, :layout=>"image_dialog"
31
31
  }
32
32
  end
33
33
  end
@@ -44,7 +44,7 @@ class GalleriesController < InheritedResources::Base
44
44
 
45
45
  def load_user
46
46
  unless params[:user_id]
47
- @user ||= (current_user ? User.find(current_user.id) : User.super_user)
47
+ @user ||= (current_user ? User.find(current_user.id) : super_user)
48
48
  end
49
49
  end
50
50
  helper_method :ckeditor_params, :paginated_images_for
@@ -0,0 +1,11 @@
1
+ class PagesController < InheritedResources::Base
2
+ def resource
3
+ page_id = params[:id] || Layout.current[:default_page]
4
+ if page_id.is_numeric?
5
+ @page ||= Page.find(page_id)
6
+ else
7
+ @page ||= Page.where(["pages.title.tolower() = ?", page_id.downcase])
8
+ end
9
+ end
10
+ end
11
+
@@ -5,7 +5,7 @@ class ProfilesController < InheritedResources::Base
5
5
 
6
6
  def load_current_user
7
7
  unless params[:user_id]
8
- @user ||= (current_user ? User.find(current_user.id) : User.super_user)
8
+ @user ||= (current_user ? User.find(current_user.id) : super_user)
9
9
  end
10
10
  end
11
11
 
@@ -0,0 +1,10 @@
1
+ module BlogsHelper
2
+ def include_ckeditor
3
+ content_for :head do
4
+ javascript_include_tag('/ckeditor/ckeditor.js',
5
+ '/ckeditor/adapters/jquery.js',
6
+ "galleries/configure_ckeditor.js")
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,11 @@
1
+ module PagesHelper
2
+ def include_ckeditor
3
+ content_for :head do
4
+ javascript_include_tag('/ckeditor/ckeditor.js',
5
+ '/ckeditor/adapters/jquery.js',
6
+ "galleries/configure_ckeditor.js")
7
+ end
8
+ end
9
+
10
+ end
11
+
@@ -1,23 +1,40 @@
1
1
  class Ability
2
2
  include CanCan::Ability
3
+ initializer :init_wheels
3
4
 
4
5
  def initialize(user)
6
+ initializers.each{|t| self.send(t, user)}
7
+ end
8
+
9
+ def init_wheels(user)
5
10
  can :read, :all
6
11
  return cannot :read, User unless user
12
+ roles = Role.all
7
13
  user ||= User.new
14
+ def roles.find_by_name(name); self.select{|t| t.name==name}[0]; end;
8
15
  case user.role_id
9
- when Role::SUPER
16
+ when roles.find_by_name("Super")
10
17
  can :manage, :all
11
- when Role::ADMIN
18
+ when roles.find_by_name("Admin")
12
19
  can :manage, :all
13
- when Role::USER
20
+ when roles.find_by_name("User")
14
21
  can :manage, Gallery, :user_id => user.id
15
22
  can :manage, Blog, :user_id => user.id
16
23
  can :edit, Profile, :user_id => user.id
17
24
  cannot :read, User
18
25
  end
19
26
  can :read, :all
27
+ end
28
+
20
29
 
30
+ def self.initializer(*method_names)
31
+ method_names.each{|t| initializers << t}
21
32
  end
33
+
34
+ def initializers
35
+ @initializers ||= []
36
+ end
37
+
38
+
22
39
  end
23
40
 
data/app/models/blog.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class Blog < ActiveRecord::Base
2
+ acts_as_taggable
2
3
  belongs_to :user
3
- validates_presence_of :user_id
4
+ validates_presence_of :user_id, :title
4
5
  has_many :images
5
6
  cattr_reader :per_page
6
7
  @@per_page = 5
data/app/models/image.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  class Image < ActiveRecord::Base
2
2
  belongs_to :gallery
3
+ acts_as_taggable
3
4
  has_attached_file :image,
4
5
  :storage => :s3,
5
6
  :s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
6
- :path => "/:style/:filename"
7
+ :path => "/images/:style/:filename",
8
+ :styles => { :medium => "300x300>", :thumb => "100x100>" }
7
9
  end
8
10
 
@@ -0,0 +1,5 @@
1
+ class Page < ActiveRecord::Base
2
+ has_many :images
3
+
4
+ end
5
+
@@ -0,0 +1,2 @@
1
+ class PageRevision < ActiveRecord::Base
2
+ end
@@ -1,4 +1,5 @@
1
1
  class Profile < ActiveRecord::Base
2
+ acts_as_tagger
2
3
  belongs_to :user
3
4
  validates_uniqueness_of :alias
4
5
  has_attached_file :image,
@@ -0,0 +1,4 @@
1
+ class ActsAsTaggableOn::Tagging
2
+
3
+ end
4
+
data/app/models/user.rb CHANGED
@@ -1,16 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
2
  before_create :create_profile
3
3
  belongs_to :role
4
-
5
- # Include default devise modules. Others available are:
6
- # :token_authenticatable, :confirmable, :lockable and :timeoutable
7
- devise :database_authenticatable, :registerable, :confirmable, :token_authenticatable,
8
- :recoverable, :rememberable, :trackable, :validatable
9
-
10
- def self.super_user
11
- @@super_user ||= User.where(:role_id=>Role::SUPER).first
12
- end
13
-
14
4
  has_many :blogs, :dependent => :destroy
15
5
  has_one :profile, :dependent => :destroy
16
6
  has_many :galleries, :dependent => :destroy
@@ -19,6 +9,16 @@ class User < ActiveRecord::Base
19
9
  self.profile ||= Profile.create(:user => self)
20
10
  end
21
11
 
12
+ def role?(role)
13
+ if role.kind_of?(Role)
14
+ return role==self.role
15
+ elsif role.is_numeric?
16
+ return self.role_id==role
17
+ else
18
+ return self.role.name.underscore==role.underscore
19
+ end
20
+ end
21
+
22
22
  def role=(role)
23
23
  if role.kind_of? Role
24
24
  self.role_id = role.id
@@ -37,8 +37,13 @@ class User < ActiveRecord::Base
37
37
  save
38
38
  end
39
39
 
40
+ # Include default devise modules. Others available are:
41
+ # :token_authenticatable, :confirmable, :lockable and :timeoutable
42
+ devise :database_authenticatable, :registerable,
43
+ :recoverable, :rememberable, :trackable, :validatable,
44
+ :token_authenticatable, :confirmable, :lockable, :timeoutable
45
+
40
46
  # Setup accessible (or protected) attributes for your model
41
- attr_accessible :email, :password, :password_confirmation,
42
- :blogs, :profile, :role, :galleries
47
+ attr_accessible :email, :password, :password_confirmation
43
48
  end
44
49
 
@@ -1,13 +1,4 @@
1
- = content_for(:head) do
2
- = javascript_include_tag '/ckeditor/ckeditor.js'
3
- = javascript_include_tag '/ckeditor/adapters/jquery.js'
4
- :javascript
5
- $(function(){
6
- config = {
7
- filebrowserBrowseUrl : '#{galleries_path}'
8
- };
9
- $('.ckeditor_textarea').ckeditor(config);
10
- });
1
+ - include_ckeditor
11
2
 
12
3
  = form_for [@blog.user, @blog], :html=>{:multipart=>true} do |f|
13
4
  -if @blog.errors.any?
@@ -20,6 +11,9 @@
20
11
  .field
21
12
  = f.label :title
22
13
  = f.text_field :title
14
+ .field
15
+ = f.label "tag_list"
16
+ .tag_list= f.text_area :tag_list
23
17
  .field
24
18
  = f.label :body
25
19
  = f.text_area :body, :class=>'ckeditor_textarea'
@@ -17,3 +17,7 @@
17
17
 
18
18
  = will_paginate @blogs
19
19
 
20
+ - content_for(:tags) do
21
+ - for tag in @tags
22
+ %li= link_to tag.name, user_blogs_path(@user, :tag=>tag.name)
23
+
@@ -1,9 +1,8 @@
1
- %p
2
- %b Title:
3
- = @blog.title
1
+ %h1= @blog.title
2
+ .tag_list!= tag_list @blog
4
3
  %p
5
4
  %b Body:
6
- = raw @blog.body
5
+ != raw @blog.body
7
6
  = link_to 'Edit', edit_resource_url
8
7
  \|
9
8
  = link_to 'Back', collection_url
@@ -24,6 +24,7 @@
24
24
  = form_for [@gallery, Image.new(:gallery=>@gallery)], :html=>{:id=>'upload', :multipart=>true} do |f|
25
25
  - params.slice(:CKEditor, :CKEditorFuncNum, :langCode).each do |key, val|
26
26
  = hidden_field_tag key, val
27
- = f.file_field :image
28
- = f.submit :disable_with=>"Uploading..."
27
+ .upload_field= f.file_field :image
28
+ .tag_field= f.text_field :tag_list
29
+ = f.submit "Upload Image", :disable_with=>"Uploading..."
29
30
 
@@ -11,9 +11,9 @@
11
11
 
12
12
  %h1= gallery.name.empty? ? "Name your gallery" : gallery.name
13
13
  - if can? :update, gallery
14
- = link_to 'Edit', edit_gallery_path(gallery)
14
+ = link_to 'Edit', edit_gallery_path(gallery, ckeditor_params)
15
15
  - if can? :manage, gallery
16
- = link_to 'Destroy', gallery, "data-confirm"=>"You'll shoot your eye out!", :method=>"delete"
16
+ = link_to 'Destroy', gallery_path(gallery, ckeditor_params), "data-confirm"=>"You'll shoot your eye out!", :method=>"delete"
17
17
  %ul#image_gallery
18
18
  - images.each do |image|
19
19
  %li
@@ -1,4 +1,4 @@
1
- = render :partial => "show", :locals=>{:images=>images, :gallery=>@gallery}
1
+ = render :partial => "show", :locals=>{:images=>@images, :gallery=>@gallery}
2
2
 
3
- = will_paginate images
3
+ = will_paginate @images
4
4
 
@@ -0,0 +1,48 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title Your Awesome Web Site
5
+ = csrf_meta_tag
6
+ /[if lt IE 9]
7
+ = javascript_include_tag 'html5'
8
+ = javascript_include_tag :defaults, "loadbehind.js", "jquery.growl.js"
9
+ = stylesheet_link_tag 'menu.css','dreamy'
10
+ = yield(:head)
11
+
12
+ :javascript
13
+ function setTitle(title){
14
+ $('title').html(title);
15
+ }
16
+ %body
17
+ #wrapper
18
+ #header
19
+ %h1 Artful Dodgin
20
+ #menu
21
+ %ul
22
+ %li
23
+ %a{:href => "/profile"} Profile
24
+ %li
25
+ %a{:href => "/blog"} Blog
26
+ %li
27
+ %a{:href => "/galleries"} Galleries
28
+ #sidebar
29
+ #feed
30
+ %a.feed-button{:href=>'/blog.xml'}
31
+ %ul
32
+ = yield(:tags)
33
+ #sidebar-bottom
34
+ \&nbsp;
35
+ #content
36
+ = yield
37
+ #footer
38
+ #footer-valid
39
+ %a{:href => "http://validator.w3.org/check/referer"} xhtml
40
+ |
41
+ %a{:href => "http://www.ginger-ninja.net/"} ginger ninja!
42
+ - if user_signed_in?
43
+ Hi #{link_to current_user.profile.alias, user_profile_path(current_user)}#{link_to('Logout', destroy_user_session_path)}
44
+ - else
45
+ = link_to('Log in', new_user_session_path)
46
+ #copyright
47
+ Copyright &copy; 2010 #{link_to "Apycom jQuery Menus", "http://apycom.com/"}
48
+
@@ -0,0 +1,19 @@
1
+ - include_ckeditor
2
+
3
+ = form_for @page do |f|
4
+ -if @page.errors.any?
5
+ #errorExplanation
6
+ %h2= "#{pluralize(@page.errors.count, "error")} prohibited this page from being saved:"
7
+ %ul
8
+ - @page.errors.full_messages.each do |msg|
9
+ %li= msg
10
+
11
+ .field
12
+ = f.label :title
13
+ = f.text_field :title
14
+ .field
15
+ = f.label :body
16
+ = f.text_area :body, :class=>'ckeditor_textarea'
17
+ .actions
18
+ = f.submit 'Save'
19
+
@@ -0,0 +1,7 @@
1
+ %h1 Editing page
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @page
6
+ \|
7
+ = link_to 'Back', pages_path
@@ -0,0 +1,21 @@
1
+ %h1 Listing pages
2
+
3
+ %table
4
+ %tr
5
+ %th Title
6
+ %th Body
7
+ %th
8
+ %th
9
+ %th
10
+
11
+ - @pages.each do |page|
12
+ %tr
13
+ %td= page.title
14
+ %td= page.body
15
+ %td= link_to 'Show', page
16
+ %td= link_to 'Edit', edit_page_path(page)
17
+ %td= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete
18
+
19
+ %br
20
+
21
+ = link_to 'New page', new_page_path
@@ -0,0 +1,5 @@
1
+ %h1 New page
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', pages_path
@@ -0,0 +1,6 @@
1
+ %h1= @page.title
2
+ .page_content!= @page.body
3
+
4
+ - if can? :edit, @page
5
+ = link_to 'Edit', edit_page_path(@page)
6
+
@@ -1,4 +1,4 @@
1
- class AddFieldsToBlogs < ActiveRecord::Migration
1
+ class CreateBlogs < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :blogs do |t|
4
4
  t.integer :user_id
@@ -4,9 +4,6 @@ class CreateRoles < ActiveRecord::Migration
4
4
  t.string :name
5
5
  t.timestamps
6
6
  end
7
- Role.create(:name=>'Super')
8
- Role.create(:name=>'Admin')
9
- Role.create(:name=>'User')
10
7
  end
11
8
 
12
9
  def self.down
@@ -7,13 +7,13 @@ class InsertAdminUserAndRoles < ActiveRecord::Migration
7
7
  :password=>"<%= user_password %>",
8
8
  :confirmed_at=>DateTime::now,
9
9
  :role=>:super)
10
- user.profile.attributes = {
10
+ Profile.create(
11
11
  :first_name => "<%= user_first_name %>",
12
12
  :last_name => "<%= user_last_name %>",
13
13
  :blog_title => "<%= user_blog_title %>",
14
- :alias => "<%= user_alias %>"
15
- }
16
- user.profile.save
14
+ :alias => "<%= user_alias %>",
15
+ :user => user
16
+ )
17
17
  end
18
18
 
19
19
  def self.down
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kevin Faustino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate app_template Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,18 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/generated_attribute'
4
+ require 'rails/generators/active_record'
5
+
6
+
7
+ class AppLayoutGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+ source_root File.expand_path('../../../../', __FILE__)
10
+ require File.join(File.dirname(__FILE__), 'core_extensions.rb')
11
+ desc "Installs files needed for App Template gem."
12
+
13
+ def copy_files
14
+ template a= 'app/views/layouts/application.html.haml',
15
+ a
16
+ end
17
+ end
18
+
@@ -0,0 +1,51 @@
1
+ module Rails
2
+ module Generators
3
+ module Actions
4
+
5
+ attr_accessor :stategies
6
+ attr_accessor :recipes
7
+ attr_reader :template_options
8
+
9
+ def initialize_templater
10
+ self.recipes = []
11
+ @stategies = []
12
+ @template_options = {}
13
+ end
14
+
15
+ def execute_stategies
16
+ stategies.each {|stategy| stategy.call }
17
+ end
18
+
19
+ def recipe(name)
20
+ recipes << name
21
+ File.join File.dirname(__FILE__), 'recipes', "#{name}.rb"
22
+ end
23
+
24
+ # TODO: Refactor loading of files
25
+
26
+ def load_snippet(name, group)
27
+ path = File.expand_path name, snippet_path(group)
28
+ File.read path
29
+ end
30
+
31
+ def load_template(name, group, match={})
32
+ path = File.expand_path name, template_path(group)
33
+ contents = File.read path
34
+ match.each do |key, value|
35
+ contents.gsub! "\%#{key.to_s}\%", value
36
+ end
37
+ contents
38
+ end
39
+
40
+ def snippet_path(name)
41
+ File.join(File.dirname(__FILE__), 'snippets', name)
42
+ end
43
+
44
+ def template_path(name)
45
+ File.join(File.dirname(__FILE__), 'templates', name)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kevin Faustino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate app_template Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,51 @@
1
+ module Rails
2
+ module Generators
3
+ module Actions
4
+
5
+ attr_accessor :stategies
6
+ attr_accessor :recipes
7
+ attr_reader :template_options
8
+
9
+ def initialize_templater
10
+ self.recipes = []
11
+ @stategies = []
12
+ @template_options = {}
13
+ end
14
+
15
+ def execute_stategies
16
+ stategies.each {|stategy| stategy.call }
17
+ end
18
+
19
+ def recipe(name)
20
+ recipes << name
21
+ File.join File.dirname(__FILE__), 'recipes', "#{name}.rb"
22
+ end
23
+
24
+ # TODO: Refactor loading of files
25
+
26
+ def load_snippet(name, group)
27
+ path = File.expand_path name, snippet_path(group)
28
+ File.read path
29
+ end
30
+
31
+ def load_template(name, group, match={})
32
+ path = File.expand_path name, template_path(group)
33
+ contents = File.read path
34
+ match.each do |key, value|
35
+ contents.gsub! "\%#{key.to_s}\%", value
36
+ end
37
+ contents
38
+ end
39
+
40
+ def snippet_path(name)
41
+ File.join(File.dirname(__FILE__), 'snippets', name)
42
+ end
43
+
44
+ def template_path(name)
45
+ File.join(File.dirname(__FILE__), 'templates', name)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+