simonmenke-mr_henry 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/License.txt +20 -0
  2. data/README +8 -0
  3. data/about.yml +7 -0
  4. data/app/controllers/lalala/base_controller.rb +8 -0
  5. data/app/helpers/lalala/base_helper.rb +47 -0
  6. data/app/helpers/lalala/tabs_helper.rb +96 -0
  7. data/app/views/lalala/layouts/application.html.erb +39 -0
  8. data/config/routes.rb +0 -0
  9. data/generators/mr_resource/USAGE +25 -0
  10. data/generators/mr_resource/mr_resource_generator.rb +103 -0
  11. data/generators/mr_resource/templates/controller.rb +24 -0
  12. data/generators/mr_resource/templates/functional_test.rb +45 -0
  13. data/generators/mr_resource/templates/helper.rb +2 -0
  14. data/generators/mr_resource/templates/partial_form.html.erb +14 -0
  15. data/generators/mr_resource/templates/partial_item.html.erb +3 -0
  16. data/generators/mr_resource/templates/view_edit.html.erb +2 -0
  17. data/generators/mr_resource/templates/view_index.html.erb +7 -0
  18. data/generators/mr_resource/templates/view_new.html.erb +2 -0
  19. data/generators/mr_resource/templates/view_show.html.erb +14 -0
  20. data/lib/mr_henry.rb +4 -0
  21. data/lib/mr_henry/action_controller.rb +5 -0
  22. data/lib/mr_henry/action_controller/handles_resource.rb +85 -0
  23. data/lib/mr_henry/generator.rb +5 -0
  24. data/lib/mr_henry/generator/create.rb +68 -0
  25. data/lib/mr_henry/generator/destroy.rb +51 -0
  26. data/lib/mr_henry/generator/update.rb +41 -0
  27. data/lib/mr_henry/version.rb +10 -0
  28. data/lib/tasks/passenger.rake +5 -0
  29. data/public/images/error.png +0 -0
  30. data/public/images/handle.png +0 -0
  31. data/public/images/henry.png +0 -0
  32. data/public/images/pointer.gif +0 -0
  33. data/public/images/spinner.gif +0 -0
  34. data/public/images/tab-active.png +0 -0
  35. data/public/images/tab-hover.png +0 -0
  36. data/public/javascripts/c_b_s.js +16 -0
  37. data/public/javascripts/lang.cbs +69 -0
  38. data/public/javascripts/lowpro.js +320 -0
  39. data/public/stylesheets/lalala.css +367 -0
  40. data/public/stylesheets/lalala_custom.css +0 -0
  41. data/rails/init.rb +35 -0
  42. data/setup/setup.rb +6 -0
  43. metadata +149 -0
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIX_ME:author
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.
data/README ADDED
@@ -0,0 +1,8 @@
1
+
2
+ Install
3
+
4
+ environment.rb:
5
+ config.gem "simonmenke-mr_henry", :lib => 'mr_henry', :source => "http://gems.github.com"
6
+
7
+ bash:
8
+ diamonds setup # only the first time
data/about.yml ADDED
@@ -0,0 +1,7 @@
1
+ name: mr_henry
2
+ github: simonmenke
3
+ description: FIX_ME:description
4
+ author: Simon Menke
5
+ email: simon.menke@gmail.com
6
+ dependencies:
7
+ - simonmenke-diamonds >= 0.0.1
@@ -0,0 +1,8 @@
1
+
2
+ class Lalala::BaseController < ApplicationController
3
+
4
+ layout 'lalala/layouts/application'
5
+
6
+ include AuthenticatedSystem
7
+ before_filter :login_required
8
+ end
@@ -0,0 +1,47 @@
1
+ module Lalala::BaseHelper
2
+
3
+ def menu_item(name, url, *args)
4
+ options = args.extract_options!
5
+ options[:condition] ||= Proc.new { |ctx|
6
+ hash = ctx.send("hash_for_#{url}", *args)
7
+ params[:controller] == hash[:controller]
8
+ }
9
+
10
+ final_url = send(url, *args)
11
+ content = image_tag('pointer.gif', :class => "pointer")+link_to(name, final_url)
12
+ content_tag :div, content, :class => (["item", ("active" if options[:condition].call(self))].join(' '))
13
+ end
14
+
15
+ def link_to_modal(*args)
16
+ link_to_function(*args) do |page|
17
+ page << "Modalbox.show(this.href, {title: this.title, width: 750});"
18
+ end
19
+ end
20
+
21
+ def boolean(bool)
22
+ bool ? 'yes' : 'no'
23
+ end
24
+
25
+ def icon_for(path)
26
+ case File.extname(path)
27
+ when '.ods' then 'page_doc.png'
28
+ when '.doc' then 'page_doc.png'
29
+ when '.docx' then 'page_doc.png'
30
+ when '.html' then 'page_html.png'
31
+ when '.pdf' then 'page_pdf.png'
32
+ when '.ppt' then 'page_ppt.png'
33
+ when '.pptx' then 'page_ppt.png'
34
+ when '.xls' then 'page_xls.png'
35
+ when '.xlsx' then 'page_xls.png'
36
+ when '.zip' then 'page_zip.png'
37
+ when '.tar' then 'page_zip.png'
38
+ when '.gz' then 'page_zip.png'
39
+ else 'page_other.png'
40
+ end
41
+ end
42
+
43
+ def icon_tag_for(path)
44
+ image_tag(icon_for(path))
45
+ end
46
+
47
+ end
@@ -0,0 +1,96 @@
1
+
2
+ module Lalala::TabsHelper
3
+
4
+ def tabs(&block)
5
+
6
+ concat("<div id=\"tabs\">", block.binding)
7
+ tabs = ::Lalala::TabsHelper::Proxy.new(self, block.binding, request)
8
+ block.call(tabs)
9
+ tabs.to_html
10
+ concat("</div>", block.binding)
11
+
12
+ end
13
+
14
+ class Proxy
15
+
16
+ def initialize(template, binding, request)
17
+ @template = template
18
+ @request = request
19
+ @binding = binding
20
+ @tabs = []
21
+ end
22
+
23
+ def url_for(*args)
24
+ @template.url_for(*args)
25
+ end
26
+
27
+ def link_to(*args)
28
+ @template.link_to(*args)
29
+ end
30
+
31
+ def concat(*args)
32
+ @template.concat(*args)
33
+ end
34
+
35
+ def tab(*args)
36
+ options = args.extract_options!
37
+ conditions = options.delete(:active)
38
+ conditions ||= options.delete(:if)
39
+
40
+ case conditions
41
+ when String then conditions = [conditions]
42
+ when Regexp then conditions = [conditions]
43
+ when Hash then conditions = [url_for(conditions)]
44
+ when Array
45
+ if (conditions.any? do |condition|
46
+ condition.is_a? Symbol or
47
+ condition.is_a? ActiveRecord::Base
48
+ end)
49
+ conditions = [url_for(conditions)]
50
+ end
51
+ end
52
+
53
+ conditions.collect! do |condition|
54
+ case condition
55
+ when String then Regexp.new("^"+Regexp.escape(condition), true)
56
+ when Regexp then condition
57
+ end
58
+ end
59
+
60
+ @tabs << [args, options, conditions]
61
+ end
62
+
63
+ def active_tab_index
64
+ return @active_tab_index unless @active_tab_index.nil?
65
+
66
+ best_match_index = 0
67
+ best_match_score = 0
68
+
69
+ @tabs.each_with_index do |(args, options, conditions), i|
70
+ conditions.each do |condition|
71
+ match = condition.match(@request.path)
72
+ if (!match.nil?) and (match[0].length > best_match_score)
73
+ best_match_index = i
74
+ best_match_score = match[0].length
75
+ end
76
+ end
77
+ end
78
+
79
+ @active_tab_index = best_match_index
80
+ end
81
+
82
+ def to_html
83
+ @tabs.each_with_index do |(args, options, conditions), i|
84
+
85
+ options[:class] = [options[:class],
86
+ ("active" if active_tab_index == i)
87
+ ].compact.join(' ')
88
+ args << options
89
+
90
+ concat(link_to(*args), @binding)
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+ <title>Lalala :: MrHenry</title>
8
+ <%= stylesheet_link_tag "lalala", "lalala_custom" %>
9
+ <%= javascript_include_tag :all %>
10
+ </head>
11
+ <body>
12
+
13
+ <div id="sidebar">
14
+ <% if logged_in? %>
15
+ <div id="menu-shadow">
16
+ <div id="menu">
17
+
18
+ <%= menu_item("Users", :lalala_users_path) %>
19
+ <%= menu_item("Logout", :lalala_logout_path) %>
20
+
21
+ </div>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+
26
+ <div class="shadow">
27
+ <div class="header">
28
+ <h1>MrHenry</h1>
29
+ </div>
30
+ </div>
31
+
32
+ <div class="shadow">
33
+ <div class="container">
34
+ <%= yield %>
35
+ </div>
36
+ </div>
37
+
38
+ </body>
39
+ </html>
data/config/routes.rb ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views, along with a full test suite. The resource is ready to use as a
4
+ starting point for your restful, resource-oriented application.
5
+
6
+ Pass the name of the model, either CamelCased or under_scored, as the first
7
+ argument, and an optional list of attribute pairs.
8
+
9
+ Attribute pairs are column_name:sql_type arguments specifying the
10
+ model's attributes. Timestamps are added by default, so you don't have to
11
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
12
+
13
+ You don't have to think up every attribute up front, but it helps to
14
+ sketch out a few so you can start working with the resource immediately.
15
+
16
+ For example, `scaffold post title:string body:text published:boolean`
17
+ gives you a model with those three attributes, a controller that handles
18
+ the create/show/update/destroy, forms to create and edit your posts, and
19
+ an index that lists them all, as well as a map.resources :posts
20
+ declaration in config/routes.rb.
21
+
22
+ Examples:
23
+ `./script/generate mr_resource post` # no attributes, view will be anemic
24
+ `./script/generate mr_resource post title:string body:text published:boolean`
25
+ `./script/generate mr_resource purchase order_id:integer amount:decimal`
@@ -0,0 +1,103 @@
1
+ ::Rails::Generator::Commands::Create.send :include, ::MrHenry::Generator::Create
2
+ ::Rails::Generator::Commands::Update.send :include, ::MrHenry::Generator::Update
3
+ ::Rails::Generator::Commands::Destroy.send :include, ::MrHenry::Generator::Destroy
4
+
5
+ class MrResourceGenerator < Rails::Generator::NamedBase
6
+ default_options :skip_timestamps => false, :skip_migration => false
7
+
8
+ attr_reader :controller_name,
9
+ :controller_class_path,
10
+ :controller_file_path,
11
+ :controller_class_nesting,
12
+ :controller_class_nesting_depth,
13
+ :controller_class_name,
14
+ :controller_underscore_name,
15
+ :controller_singular_name,
16
+ :controller_plural_name
17
+ alias_method :controller_file_name, :controller_underscore_name
18
+ alias_method :controller_table_name, :controller_plural_name
19
+
20
+ def initialize(runtime_args, runtime_options = {})
21
+ super
22
+
23
+ @controller_name = "Lalala::"+@name.pluralize
24
+
25
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
26
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
27
+ @controller_singular_name=base_name.singularize
28
+ if @controller_class_nesting.empty?
29
+ @controller_class_name = @controller_class_name_without_nesting
30
+ else
31
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
32
+ end
33
+ end
34
+
35
+ def manifest
36
+ record do |m|
37
+ # Check for class naming collisions.
38
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
39
+ m.class_collisions(class_path, "#{class_name}")
40
+
41
+ # Controller, helper, views, test and stylesheets directories.
42
+ m.directory(File.join('app/models', class_path))
43
+ m.directory(File.join('app/controllers', controller_class_path))
44
+ m.directory(File.join('app/helpers', controller_class_path))
45
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
46
+ m.directory(File.join('app/views/layouts', controller_class_path))
47
+ m.directory(File.join('test/functional', controller_class_path))
48
+ m.directory(File.join('test/unit', class_path))
49
+ m.directory(File.join('public/stylesheets', class_path))
50
+
51
+ for action in scaffold_views
52
+ m.template(
53
+ "view_#{action}.html.erb",
54
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
55
+ )
56
+ end
57
+
58
+ m.template(
59
+ "partial_form.html.erb",
60
+ File.join('app/views', controller_class_path, controller_file_name, "_form.html.erb")
61
+ )
62
+ m.template(
63
+ "partial_item.html.erb",
64
+ File.join('app/views', controller_class_path, controller_file_name, "_#{name.underscore}.html.erb")
65
+ )
66
+
67
+ m.template(
68
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
69
+ )
70
+
71
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
72
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
73
+
74
+ # m.route_lalala_resources controller_file_name
75
+ # m.lalala_menu(controller_file_name.humanize, controller_file_name)
76
+
77
+ m.dependency 'model', [name] + @args, :collision => :skip
78
+ end
79
+ end
80
+
81
+ protected
82
+ # Override with your own usage banner.
83
+ def banner
84
+ "Usage: #{$0} scaffold ModelName [field:type, field:type]"
85
+ end
86
+
87
+ def add_options!(opt)
88
+ opt.separator ''
89
+ opt.separator 'Options:'
90
+ opt.on("--skip-timestamps",
91
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
92
+ opt.on("--skip-migration",
93
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
94
+ end
95
+
96
+ def scaffold_views
97
+ %w[ index show new edit ]
98
+ end
99
+
100
+ def model_name
101
+ class_name.demodulize
102
+ end
103
+ end
@@ -0,0 +1,24 @@
1
+ class <%= controller_class_name %>Controller < Lalala::BaseController
2
+
3
+ resources :<%= table_name %>
4
+
5
+ def create
6
+ <%= file_name %>.save!
7
+ redirect_to [:lalala, <%= file_name %>]
8
+ rescue ActiveRecord::RecordInvalid => e
9
+ render :action => "new"
10
+ end
11
+
12
+ def update
13
+ <%= file_name %>.update_attributes!(params[:<%= file_name %>])
14
+ redirect_to [:lalala, <%= file_name %>]
15
+ rescue ActiveRecord::RecordInvalid => e
16
+ render :action => "edit"
17
+ end
18
+
19
+ def destroy
20
+ <%= file_name %>.destroy
21
+ redirect_to lalala_<%= table_name %>_path
22
+ end
23
+
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_should_get_index
5
+ get :index
6
+ assert_response :success
7
+ assert_not_nil assigns(:<%= table_name %>)
8
+ end
9
+
10
+ def test_should_get_new
11
+ get :new
12
+ assert_response :success
13
+ end
14
+
15
+ def test_should_create_<%= file_name %>
16
+ assert_difference('<%= class_name %>.count') do
17
+ post :create, :<%= file_name %> => { }
18
+ end
19
+
20
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
21
+ end
22
+
23
+ def test_should_show_<%= file_name %>
24
+ get :show, :id => <%= table_name %>(:one).id
25
+ assert_response :success
26
+ end
27
+
28
+ def test_should_get_edit
29
+ get :edit, :id => <%= table_name %>(:one).id
30
+ assert_response :success
31
+ end
32
+
33
+ def test_should_update_<%= file_name %>
34
+ put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
35
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
36
+ end
37
+
38
+ def test_should_destroy_<%= file_name %>
39
+ assert_difference('<%= class_name %>.count', -1) do
40
+ delete :destroy, :id => <%= table_name %>(:one).id
41
+ end
42
+
43
+ assert_redirected_to <%= table_name %>_path
44
+ end
45
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end