mack 0.7.0.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGELOG +34 -0
  2. data/README +6 -13
  3. data/bin/env_handler.rb +10 -0
  4. data/bin/gem_load_path.rb +25 -0
  5. data/bin/mack +1 -0
  6. data/bin/mackery +22 -0
  7. data/bin/mackery-console +16 -0
  8. data/bin/mackery-server +41 -0
  9. data/lib/mack.rb +7 -1
  10. data/lib/mack/controller/controller.rb +5 -4
  11. data/lib/mack/controller/request.rb +19 -1
  12. data/lib/mack/errors/errors.rb +8 -8
  13. data/lib/mack/generators/controller_generator/controller_generator.rb +1 -1
  14. data/lib/mack/generators/mack_application_generator/templates/app/views/layouts/application.html.erb.template +1 -2
  15. data/lib/mack/generators/mack_application_generator/templates/config/app_config/default.yml.template +2 -0
  16. data/lib/mack/generators/mack_application_generator/templates/config/database.yml.template +6 -6
  17. data/lib/mack/generators/passenger_generator/passenger_generator.rb +2 -0
  18. data/lib/mack/generators/passenger_generator/templates/config.ru.template +5 -0
  19. data/lib/mack/generators/passenger_generator/templates/tmp/README.template +2 -0
  20. data/lib/mack/initialization/application.rb +39 -36
  21. data/lib/mack/initialization/boot_loader.rb +174 -0
  22. data/lib/mack/initialization/configuration.rb +83 -95
  23. data/lib/mack/initialization/console.rb +11 -0
  24. data/lib/mack/initialization/environment.rb +16 -0
  25. data/lib/mack/initialization/helpers.rb +26 -24
  26. data/lib/mack/initialization/logging.rb +81 -81
  27. data/lib/mack/initialization/plugins.rb +14 -11
  28. data/lib/mack/initialization/server/simple_server.rb +3 -3
  29. data/lib/mack/rendering/type/base.rb +1 -1
  30. data/lib/mack/rendering/type/layout.rb +1 -1
  31. data/lib/mack/rendering/type/partial.rb +1 -1
  32. data/lib/mack/rendering/type/public.rb +1 -1
  33. data/lib/mack/rendering/type/template.rb +1 -1
  34. data/lib/mack/runner.rb +2 -2
  35. data/lib/mack/runner_helpers/session.rb +3 -3
  36. data/lib/mack/sessions/cookie_session_store.rb +44 -0
  37. data/lib/mack/{controller → sessions}/session.rb +0 -0
  38. data/lib/mack/sessions/session_store_base.rb +62 -0
  39. data/lib/mack/sessions/test_session_store.rb +38 -0
  40. data/lib/mack/tasks/mack_server_tasks.rake +8 -21
  41. data/lib/mack/tasks/mack_tasks.rake +33 -6
  42. data/lib/mack/tasks/rake_rules.rake +8 -0
  43. data/lib/mack/tasks/test_tasks.rake +39 -15
  44. data/lib/mack/testing/helpers.rb +6 -39
  45. data/lib/mack/utils/content_length_handler.rb +45 -0
  46. data/lib/mack/utils/forgery_detector.rb +152 -0
  47. data/lib/mack/utils/gem_manager.rb +22 -1
  48. data/lib/mack/utils/paths.rb +154 -0
  49. data/lib/mack/utils/server.rb +8 -6
  50. data/lib/mack/version.rb +1 -1
  51. data/lib/mack/view_helpers/asset_helpers.rb +50 -0
  52. data/lib/mack/view_helpers/form_helpers.rb +52 -6
  53. data/lib/mack/view_helpers/link_helpers.rb +6 -3
  54. data/lib/mack_app.rb +12 -14
  55. data/lib/mack_core.rb +35 -14
  56. data/lib/mack_tasks.rb +35 -20
  57. metadata +23 -27
  58. data/lib/mack/tasks/cachetastic_tasks.rake +0 -58
data/CHANGELOG CHANGED
@@ -1,3 +1,37 @@
1
+ === 0.7.1
2
+ * [#153] Emails with just a single 'part' are now being sent correctly.
3
+ * [#147] Added :confirm to button helpers.
4
+ * [#146] [Diogo Almeida] Added :disable_with to submit_button form helper.
5
+ * [#145] Added rake generate:<generator_name>:desc task to 'describe' a Genosaurus generator
6
+ * [#144] INCOMPATIBILITY NOTICE: rake server is no more. Please use mackery server instead.
7
+ * [#142] INCOMPATIBILITY NOTICE: rake console is no more. Please use mackery console instead.
8
+ * [#140] Added Mack::BootLoader
9
+ * [#139] Added ability to change the pattern for test files
10
+ * [#137] Added subdomains method on request.
11
+ * [#130] Added ability to 'reload' the console
12
+ * [#129] DataMapper 0.9.5 support
13
+ * [#128] Updated json_pure to 1.1.3 and removed ruby-debug dependency
14
+ * [#127] Moved mack-paths into core
15
+ * [#126] XSS Prevention
16
+ * [#125] Cookie store is now the default session store, not cachetastic
17
+ * [#124] Opened up the session store API
18
+ * [#122] Added DataMapper session store.
19
+ * [#121] Cookie session store support.
20
+ * [#120] Added PassengerGenerator to generate the necessary files to run Mack with Passenger Phusion (mod_rails)
21
+ * [#118] Mack/mack-more can be loaded from vendor/framework/mack and vendor/framework/mack-more
22
+ * [#117] Added rake task: mack:freeze:edge
23
+ * [#107] Updated to Rack 0.4.0
24
+ * [#95] Removed deprecated model_* methods
25
+ * [#94] Removed deprecated submit_tag
26
+ * [#40] Added Mack::Utils::ContentLengthHandler so response will now have 'Content-Length' in its header.
27
+ * [#21] Asset Hosts
28
+ * gem: rack 0.4.0
29
+ * gem: json_pure 1.1.3
30
+ * gem: data_mapper 0.9.5
31
+ * gem: genosaurus 1.2.4
32
+ * gem: ezcrypto 0.7
33
+ * gem: facets 2.4.4
34
+
1
35
  === 0.7.0.1
2
36
  gem: application_configuration 1.5.3
3
37
  gem: cachetastic 1.7.4
data/README CHANGED
@@ -12,23 +12,16 @@ First things first, let's generate your application:
12
12
  $ mack <app_name>
13
13
 
14
14
  To run a Mack application:
15
- $ rake mack:server:start
15
+ $ mackery server
16
16
 
17
- It will try and run the app using the following servers in this order:
18
- * Thin
19
- * Mongrel
20
- * WEBrick
21
-
22
- rake script:server takes the following options:
23
- $ rake server PORT=<port> Mack.env=<environment> HANDLER=<rack_handler>
24
-
25
- The port and rack_handler flags don't apply if you're using Thin[http://code.macournoyer.com/thin] to run the app, which is the default if it is installed. Use the thin.yml file in your application's config directory to configure Thin. The rack_handler one will allow you to switch which server is used to run the app. See Rack for more Rack::Handlers.
17
+ mackery server takes the following options:
18
+ $ mackery server -p <port> -e <environment> -h <rack_handler>
26
19
 
27
- The environment can also be changed like this:
28
- $ rake mack:server:start#<environment>
20
+ The rack_handler one will allow you to switch which server is used to run the app. See Rack for more Rack::Handlers.
29
21
 
30
22
  You can also run:
31
- $ rake mack:console
23
+ $ mackery console
24
+
32
25
  This will give you console level access to your application.
33
26
 
34
27
 
@@ -0,0 +1,10 @@
1
+ if ARGV.include?("-e")
2
+ ENV["MACK_ENV"] = ARGV[ARGV.index("-e") + 1] unless ENV["MACK_ENV"]
3
+ end
4
+
5
+ @mack_gem_version = nil
6
+ begin
7
+ rakefile = File.read(File.join(FileUtils.pwd, 'Rakefile'))
8
+ @mack_gem_version = rakefile.match(/gem.['"]mack['"].+['"](.+)['"]/).captures.first
9
+ rescue Exception => e
10
+ end
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+ require File.join(File.dirname(__FILE__), "env_handler")
3
+
4
+ vendor_path = File.join(FileUtils.pwd, 'vendor')
5
+
6
+ mack_path = File.join(vendor_path, 'framework', 'mack', 'lib')
7
+ mack_more_path = File.join(vendor_path, 'framework', 'mack-more')
8
+ # gem_path = File.join(vendor_path, 'gems')
9
+
10
+ if File.exists?(mack_path)
11
+ $:.insert(0, File.expand_path(mack_path))
12
+ else
13
+ require 'rubygems'
14
+ if @mack_gem_version
15
+ gem 'mack', @mack_gem_version
16
+ else
17
+ gem 'mack'
18
+ end
19
+ end
20
+
21
+ if File.exists?(mack_more_path)
22
+ Dir.glob(File.join(mack_more_path, '*')).each_with_index do |d, i|
23
+ $:.insert(i+1, File.expand_path(File.join(d, 'lib')))
24
+ end
25
+ end
data/bin/mack CHANGED
@@ -6,6 +6,7 @@ require 'ostruct'
6
6
  require 'pp'
7
7
  require 'erb'
8
8
  require 'genosaurus'
9
+ require 'mack-facets'
9
10
  require File.join(File.dirname(__FILE__), "..", "lib", "mack", "generators", "mack_application_generator", "mack_application_generator")
10
11
 
11
12
  app = ARGV[0]
@@ -0,0 +1,22 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ @app = ARGV[0]
4
+ if @app.nil?
5
+ @app = "server"
6
+ end
7
+
8
+ ARGV.shift # get rid of the app name, cause we don't need it.
9
+ @app = @app.strip.downcase
10
+
11
+ case @app
12
+ when "start"
13
+ @app = "server"
14
+ else
15
+ end
16
+
17
+ require File.join(File.dirname(__FILE__), "env_handler")
18
+
19
+ cmd = "mackery-#{@app} #{ARGV.join(" ")}"
20
+ cmd << " _#{@mack_gem_version}_" if @mack_gem_version
21
+ # puts cmd
22
+ system cmd
@@ -0,0 +1,16 @@
1
+ #!/usr/local/bin/ruby
2
+ # require File.join(File.dirname(__FILE__), "options_handler")
3
+
4
+ require File.join(File.dirname(__FILE__), "env_handler")
5
+
6
+ require File.join(File.dirname(__FILE__), "gem_load_path")
7
+
8
+ libs = []
9
+ libs << "-r irb/completion"
10
+ mack_lib_path = File.join(FileUtils.pwd, 'vendor', 'framework', 'mack', 'lib', 'mack')
11
+ if File.exists?(mack_lib_path)
12
+ libs << "-r #{File.join(mack_lib_path, 'initialization', 'console')}"
13
+ else
14
+ libs << "-r #{File.join(File.dirname(__FILE__), '..', 'lib', 'mack', 'initialization', 'console')}"
15
+ end
16
+ system "irb #{libs.join(" ")} --simple-prompt"
@@ -0,0 +1,41 @@
1
+ #!/usr/local/bin/ruby
2
+ # require File.join(File.dirname(__FILE__), "options_handler")
3
+
4
+ require File.join(File.dirname(__FILE__), "env_handler")
5
+
6
+ require File.join(File.dirname(__FILE__), "gem_load_path")
7
+
8
+ require 'rubygems'
9
+
10
+ require 'fileutils'
11
+ require 'thin'
12
+
13
+ require 'mack'
14
+
15
+ handler = "thin"
16
+
17
+ if ARGV.include?("-h")
18
+ handler = ARGV[ARGV.index("-h") + 1]
19
+ ARGV.delete("-h")
20
+ ARGV.delete(handler)
21
+ end
22
+
23
+ if handler == "thin"
24
+ # thin_opts = ["start", ARGV]
25
+ thin_opts = []
26
+ if ARGV[0] == "start" || ARGV[0] == "stop" || ARGV[0] == "restart"
27
+ thin_opts << ARGV[0]
28
+ ARGV.shift
29
+ else
30
+ thin_opts << "start"
31
+ end
32
+ thin_opts << ARGV
33
+ # puts "thin_opts: #{thin_opts.flatten.inspect}"
34
+ Thin::Runner.new(thin_opts.flatten.reject{|a| a.match(/^_[\d\.]+_$/)}).run!
35
+ else
36
+ port = 3000
37
+ if ARGV.include?("-p")
38
+ port = ARGV[ARGV.index("-p") + 1]
39
+ end
40
+ Mack::SimpleServer.run(:handler => handler, :port => port, :environment => ENV["MACK_ENV"])
41
+ end
@@ -1,2 +1,8 @@
1
+ # require the core classes:
2
+
3
+ # puts "Loading mack from: #{File.dirname(__FILE__)}"
4
+
1
5
  require File.join(File.dirname(__FILE__), 'mack_core')
2
- require File.join(File.dirname(__FILE__), 'mack_app')
6
+
7
+ # load the environment:
8
+ Mack::Environment.load
@@ -348,9 +348,7 @@ module Mack
348
348
  # end
349
349
  # end
350
350
  #
351
- # The default layout is "#{Mack.root}/app/views/layouts/application.html.erb".
352
- #
353
- # If a layout is specified, and it doesn't exist a Mack::Errors::UnknownLayout error will be raised.
351
+ # The default layout is "#{Mack.root}/app/views/layouts/application.<format>.erb".
354
352
  def layout(lay)
355
353
  self.class_eval do
356
354
  define_method(:layout) do
@@ -367,11 +365,14 @@ module Mack
367
365
  def self.included(base)
368
366
  Mack::Controller::Registry.add(base)
369
367
  base.extend(ClassMethods)
368
+ base.extend(Mack::Utils::ForgeryDetector::ClassMethods)
369
+ base.before_filter :detect_forgery
370
370
  end
371
371
 
372
372
  # Houses a repository of all the controllers in the system.
373
373
  class Registry < Mack::Utils::RegistryList
374
- end
374
+ end
375
375
 
376
+ include Mack::Utils::ForgeryDetector
376
377
  end # Controller
377
378
  end # Mack
@@ -51,12 +51,26 @@ module Mack
51
51
  u
52
52
  end
53
53
 
54
+ # Returns all the subdomains as an array, so ["dev", "www"] would be returned for
55
+ # "dev.www.mackframework.com". You can specify a different tld_length, such as 2
56
+ # to catch ["www"] instead of ["www", "mackframework"] in "www.mackframework.co.uk".
57
+ #
58
+ # Thanks Ruby on Rails for this.
59
+ def subdomains(tld_length = 1)
60
+ return [] unless named_host?(host)
61
+ parts = host.split('.')
62
+ parts[0..-(tld_length+2)]
63
+ end
64
+
54
65
  # Examples:
55
66
  # http://example.org:80
56
67
  # https://example.org:443
57
68
  # http://example.org:8080
58
69
  def full_host_with_port
59
- full_host << ":#{self.port}"
70
+ unless full_host.match(/:#{self.port}/)
71
+ return full_host + ":#{self.port}"
72
+ end
73
+ return full_host
60
74
  end
61
75
 
62
76
  # Gives access to the request parameters. This includes 'get' parameters, 'post' parameters
@@ -81,6 +95,10 @@ module Mack
81
95
  end
82
96
 
83
97
  private
98
+ def named_host?(host)
99
+ !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
100
+ end
101
+
84
102
  def parse_params(ps)
85
103
 
86
104
  # look for date time selects:
@@ -60,14 +60,6 @@ module Mack
60
60
  end
61
61
  end # UndefinedRoute
62
62
 
63
- # Raised when a layout is specified that doesn't exist.
64
- class UnknownLayout < StandardError
65
- # Takes a layout name.
66
- def initialize(layout)
67
- super("Could not find layout in: #{File.join(Mack.root, "app", "views", layout.to_s + ".html.erb")}")
68
- end
69
- end
70
-
71
63
  # Raised if an unsupported render option is supplied.
72
64
  class UnknownRenderOption < StandardError
73
65
  # Takes a render option.
@@ -111,5 +103,13 @@ module Mack
111
103
  end
112
104
  end
113
105
 
106
+ # Raised if a request (other than GET request) has an invalid authenticity token
107
+ class InvalidAuthenticityToken < StandardError
108
+ # Takes the mismatched token
109
+ def initialize(token)
110
+ super("TOKEN: #{token.to_s} is an invalid request authenticity token.")
111
+ end
112
+ end
113
+
114
114
  end # Errors
115
115
  end # Mack
@@ -24,7 +24,7 @@ class ControllerGenerator < Genosaurus
24
24
  private
25
25
  def update_routes_file # :nodoc:
26
26
  unless @actions.empty?
27
- routes = File.join(Mack.root, "config", "routes.rb")
27
+ routes = Mack::Paths.config("routes.rb")
28
28
  rf = File.open(routes).read
29
29
  unless rf.match(".resource :#{@name_plural}")
30
30
  puts "Updating routes.rb"
@@ -1,5 +1,4 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
2
 
4
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
4
  <head>
@@ -25,6 +25,8 @@ mack::session_id: _<%= @options["app"].downcase %>_session_id
25
25
 
26
26
  mack::testing_framework: <%= @options["testing_framework"] %>
27
27
 
28
+ default_secret_key: <%= String.randomize(80) %>
29
+
28
30
  # Mack provides RJS support through mack-javascript gem.
29
31
  # In order to have RJS support, you will need to perform the following steps:
30
32
  # 1. Uncomment the code below, and make sure that the framework is the one you want to use
@@ -53,17 +53,17 @@ when "data_mapper"
53
53
  development:
54
54
  default:
55
55
  adapter: sqlite3
56
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_development.db") %>
56
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_development.db") %>
57
57
 
58
58
  test:
59
59
  default:
60
60
  adapter: sqlite3
61
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_test.db") %>
61
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_test.db") %>
62
62
 
63
63
  production:
64
64
  default:
65
65
  adapter: sqlite3
66
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_production.db") %>
66
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_production.db") %>
67
67
 
68
68
  <% else -%>
69
69
  # development:
@@ -89,13 +89,13 @@ production:
89
89
 
90
90
  development:
91
91
  adapter: sqlite3
92
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_development.db") %>
92
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_development.db") %>
93
93
 
94
94
  test:
95
95
  adapter: sqlite3
96
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_test.db") %>
96
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_test.db") %>
97
97
 
98
98
  production:
99
99
  adapter: sqlite3
100
- database: <%%= File.join(Mack.root, "db", "<%= @options["app"].downcase %>_production.db") %>
100
+ database: <%%= Mack::Paths.db("<%= @options["app"].downcase %>_production.db") %>
101
101
  <% end -%>
@@ -0,0 +1,2 @@
1
+ class PassengerGenerator < Genosaurus
2
+ end
@@ -0,0 +1,5 @@
1
+ ENV["MACK_ENV"] = 'development'
2
+ require 'rubygems'
3
+ load("Rakefile")
4
+ require 'mack'
5
+ run Mack::Utils::Server.build_app
@@ -0,0 +1,2 @@
1
+ Temporary folder.
2
+ Do not delete this folder if you are using Phusion Passenger (mod_rails) to host your Mack application.
@@ -1,46 +1,49 @@
1
- # set up initializers:
2
- Mack.logger.debug "Initializing custom initializers..." unless app_config.log.disable_initialization_logging
3
- Dir.glob(File.join(Mack.root, "config", "initializers", "**/*.rb")) do |d|
4
- require d
1
+ boot_load(:initializers) do
2
+ Mack.logger.debug "Initializing custom initializers..." unless app_config.log.disable_initialization_logging
3
+ Dir.glob(Mack::Paths.initializers("**/*.rb")) do |d|
4
+ require d
5
+ end
5
6
  end
6
- Mack.logger.debug "Initializing custom gems..." unless app_config.log.disable_initialization_logging
7
- Mack::Utils::GemManager.instance.do_requires
8
-
9
- # require 'plugins':
10
- Mack.logger.debug "Initializing plugins..." unless app_config.log.disable_initialization_logging
11
- require File.join(File.dirname(__FILE__), "plugins.rb")
12
7
 
13
- # make sure that default_controller is available to other controllers
14
- path = File.join(Mack.root, "app", "controllers", "default_controller.rb")
15
- require path if File.exists?(path)
8
+ boot_load(:lib, :plugins, :gems) do
9
+ # require 'lib' files:
10
+ Mack.logger.debug "Initializing lib classes..." unless app_config.log.disable_initialization_logging
11
+ Dir.glob(Mack::Paths.lib("**/*.rb")).each do |d|
12
+ require d
13
+ end
14
+ end
16
15
 
17
- # require 'lib' files:
18
- Mack.logger.debug "Initializing lib classes..." unless app_config.log.disable_initialization_logging
19
- Dir.glob(File.join(Mack.root, "lib", "**/*.rb")).each do |d|
20
- require d
16
+ boot_load(:default_controller, :lib) do
17
+ # make sure that default_controller is available to other controllers
18
+ path = Mack::Paths.controllers("default_controller.rb")
19
+ require path if File.exists?(path)
21
20
  end
22
21
 
23
- # set up routes:
24
- Mack.logger.debug "Initializing routes..." unless app_config.log.disable_initialization_logging
25
- require File.join(Mack.root, "config", "routes")
22
+ boot_load(:routes) do
23
+ # set up routes:
24
+ Mack.logger.debug "Initializing routes..." unless app_config.log.disable_initialization_logging
25
+ require Mack::Paths.config("routes")
26
+ end
26
27
 
27
- # require 'app' files:
28
- Mack.logger.debug "Initializing 'app' classes..." unless app_config.log.disable_initialization_logging
29
- Dir.glob(File.join(Mack.root, "app", "**/*.rb")).each do |d|
30
- # puts "d: #{d}"
31
- begin
32
- require d
33
- rescue NameError => e
34
- if e.message.match("uninitialized constant")
35
- mod = e.message.gsub("uninitialized constant ", "")
36
- x =%{
37
- module ::#{mod}
38
- end
39
- }
40
- eval(x)
28
+ boot_load(:app_files, :default_controller) do
29
+ # require 'app' files:
30
+ Mack.logger.debug "Initializing 'app' classes..." unless app_config.log.disable_initialization_logging
31
+ Dir.glob(Mack::Paths.app("**/*.rb")).each do |d|
32
+ # puts "d: #{d}"
33
+ begin
41
34
  require d
42
- else
43
- raise e
35
+ rescue NameError => e
36
+ if e.message.match("uninitialized constant")
37
+ mod = e.message.gsub("uninitialized constant ", "")
38
+ x =%{
39
+ module ::#{mod}
40
+ end
41
+ }
42
+ eval(x)
43
+ require d
44
+ else
45
+ raise e
46
+ end
44
47
  end
45
48
  end
46
49
  end