spurs 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 (99) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +118 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/spurs/icons/16x16/accept.png +0 -0
  5. data/app/assets/images/spurs/icons/16x16/delete.png +0 -0
  6. data/app/assets/images/spurs/icons/16x16/info.png +0 -0
  7. data/app/assets/images/spurs/icons/16x16/warning.png +0 -0
  8. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  9. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  10. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  11. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  12. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  13. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  14. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  15. data/app/assets/images/spurs/jquery_ui_theme/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  16. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_222222_256x240.png +0 -0
  17. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_2e83ff_256x240.png +0 -0
  18. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_454545_256x240.png +0 -0
  19. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_888888_256x240.png +0 -0
  20. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_cd0a0a_256x240.png +0 -0
  21. data/app/assets/images/spurs/jquery_ui_theme/images/ui-icons_f6cf3b_256x240.png +0 -0
  22. data/app/assets/javascripts/spurs/application.js +15 -0
  23. data/app/assets/javascripts/spurs/flashes.js.coffee +30 -0
  24. data/app/assets/javascripts/spurs/flashes.js.erb +32 -0
  25. data/app/assets/javascripts/spurs/sections.js.coffee +9 -0
  26. data/app/assets/javascripts/spurs/vars.js.coffee.erb +6 -0
  27. data/app/assets/javascripts/spurs/vars.js.erb +10 -0
  28. data/app/assets/javascripts/spurs.js +20 -0
  29. data/app/assets/stylesheets/spurs/application.css +13 -0
  30. data/app/assets/stylesheets/spurs/jquery-ui-theme.css +13 -0
  31. data/app/assets/stylesheets/spurs/jquery_ui_theme/jquery-ui-1.8.16.custom.css +1320 -0
  32. data/app/assets/stylesheets/spurs/jquery_ui_theme/jquery.ui.1.8.16.ie.css +6 -0
  33. data/app/assets/stylesheets/spurs/sections.css.sass +17 -0
  34. data/app/assets/stylesheets/spurs/vcenter.css.sass +11 -0
  35. data/app/assets/stylesheets/spurs.css +14 -0
  36. data/app/controllers/spurs/application_controller.rb +4 -0
  37. data/app/controllers/spurs/flashes_controller.rb +11 -0
  38. data/app/helpers/spurs/application_helper.rb +4 -0
  39. data/app/helpers/spurs/flashes_helper.rb +4 -0
  40. data/app/views/layouts/spurs/application.html.erb +14 -0
  41. data/app/views/spurs/flashes/add_message.js.erb +3 -0
  42. data/app/views/spurs/modals/spawn.js.erb +17 -0
  43. data/config/locales/en.yml +5 -0
  44. data/config/routes.rb +6 -0
  45. data/lib/spurs/engine.rb +10 -0
  46. data/lib/spurs/flash/builder.rb +55 -0
  47. data/lib/spurs/flash/controller_mods.rb +43 -0
  48. data/lib/spurs/flash/helper.rb +161 -0
  49. data/lib/spurs/flash.rb +54 -0
  50. data/lib/spurs/modal/builder.rb +118 -0
  51. data/lib/spurs/modal/controller_mods.rb +49 -0
  52. data/lib/spurs/modal/helper.rb +25 -0
  53. data/lib/spurs/modal.rb +16 -0
  54. data/lib/spurs/nav/builder.rb +213 -0
  55. data/lib/spurs/nav/helper.rb +42 -0
  56. data/lib/spurs/nav.rb +23 -0
  57. data/lib/spurs/popover/builder.rb +7 -0
  58. data/lib/spurs/popover/helper.rb +8 -0
  59. data/lib/spurs/popover.rb +5 -0
  60. data/lib/spurs/section/collapsible_section_builder.rb +31 -0
  61. data/lib/spurs/section/helper.rb +37 -0
  62. data/lib/spurs/section.rb +15 -0
  63. data/lib/spurs/version.rb +3 -0
  64. data/lib/spurs.rb +26 -0
  65. data/lib/tasks/spurs_tasks.rake +4 -0
  66. data/test/dummy/README.rdoc +261 -0
  67. data/test/dummy/Rakefile +7 -0
  68. data/test/dummy/app/assets/javascripts/application.js +15 -0
  69. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  70. data/test/dummy/app/controllers/application_controller.rb +3 -0
  71. data/test/dummy/app/helpers/application_helper.rb +2 -0
  72. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/test/dummy/config/application.rb +56 -0
  74. data/test/dummy/config/boot.rb +10 -0
  75. data/test/dummy/config/database.yml +25 -0
  76. data/test/dummy/config/environment.rb +5 -0
  77. data/test/dummy/config/environments/development.rb +37 -0
  78. data/test/dummy/config/environments/production.rb +67 -0
  79. data/test/dummy/config/environments/test.rb +37 -0
  80. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/test/dummy/config/initializers/inflections.rb +15 -0
  82. data/test/dummy/config/initializers/mime_types.rb +5 -0
  83. data/test/dummy/config/initializers/secret_token.rb +7 -0
  84. data/test/dummy/config/initializers/session_store.rb +8 -0
  85. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  86. data/test/dummy/config/locales/en.yml +5 -0
  87. data/test/dummy/config/routes.rb +4 -0
  88. data/test/dummy/config.ru +4 -0
  89. data/test/dummy/public/404.html +26 -0
  90. data/test/dummy/public/422.html +26 -0
  91. data/test/dummy/public/500.html +25 -0
  92. data/test/dummy/public/favicon.ico +0 -0
  93. data/test/dummy/script/rails +6 -0
  94. data/test/functional/spurs/flashes_controller_test.rb +9 -0
  95. data/test/integration/navigation_test.rb +10 -0
  96. data/test/spurs_test.rb +7 -0
  97. data/test/test_helper.rb +15 -0
  98. data/test/unit/helpers/spurs/flashes_helper_test.rb +6 -0
  99. metadata +224 -0
@@ -0,0 +1,213 @@
1
+ module Spurs
2
+ module Nav
3
+ class Builder
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ @@default_tab_options = {
7
+ :icon_only => false
8
+ }
9
+
10
+ @@default_dropdown_options = {
11
+ :href => "#",
12
+ :icon_only => false
13
+ }
14
+
15
+ @args_from_helper
16
+
17
+ def initialize(opts={ })
18
+ @args_from_helper = opts.clone
19
+ end
20
+
21
+ # Create a tab
22
+ # *options
23
+ # :label => overrides display name
24
+ # :href => link for tab
25
+ # :onclick => onclick for tab
26
+ # *active
27
+ # :active => true will force the tab to be active
28
+ # :active => [{:controller => 'pages', :action => 'index'},{:controller => 'pages', :action => 'new'}]
29
+ def tab(name, options={ })
30
+ tab_tag(name, nil, nil, options)
31
+ end
32
+
33
+ def list_header(name)
34
+ content_tag(:li, name, :class => 'nav-header')
35
+ end
36
+
37
+ # Create a dropdown
38
+ # *options
39
+ # :label => overrides display name
40
+ def dropdown(name, options={ })
41
+ opts = options.merge({ :dropdown => true })
42
+ actions = options[:actions] ? options[:actions] : []
43
+ tab_tag(name, content_tag_string(:b, '', :class => "caret").html_safe, build_drop_down_menu(actions).html_safe, opts)
44
+
45
+ end
46
+
47
+ private
48
+
49
+ def tab_tag(name, content_inside_a, content_inside_li=nil, options={ })
50
+
51
+ if options.is_a?(Array) then raise "opts should be a hash! #{opts.to_json}" end
52
+
53
+ opts = @@default_tab_options.merge(@args_from_helper.merge(options))
54
+
55
+ ## Figure out the display name. Use the :label property if one is provided, otherwise use the symbol
56
+ display_name = opts[:label] ?
57
+ opts[:label] :
58
+ name.to_s.titlecase
59
+
60
+ #options for a tag
61
+ a_opts = if options[:dropdown] then
62
+ { :class => 'dropdown-toggle', 'data-toggle' => :dropdown }
63
+ else
64
+ options[:dynamic] ? { 'data-tabs' => :tabs } : { }
65
+ end
66
+
67
+
68
+ #options for li tag
69
+ li_opts = options[:dropdown] ?
70
+ { :class => 'dropdown', 'data-dropdown' => :dropdown } :
71
+ { }
72
+
73
+ ## The icon for this tab
74
+ if opts[:icon]
75
+ display_name = if opts[:icon_only]
76
+ content_tag_string(:i, nil, :class => "icon-#{opts[:icon].to_s}")
77
+ else
78
+ content_tag_string(:i, nil, :class => "icon-#{opts[:icon].to_s}").concat(display_name)
79
+ end
80
+ end
81
+
82
+ if li_opts[:class] == nil then li_opts[:class] = "" end
83
+ if a_opts[:class] == nil then a_opts[:class] = "" end
84
+
85
+
86
+ if opts[:dynamic] && (opts[:dropdown] == nil || opts[:dropdown] == false)
87
+ a_opts['data-toggle'] = :tab
88
+ end
89
+
90
+
91
+ # Process :href and :onclick
92
+ if opts[:href] then
93
+ a_opts[:href] = opts[:href]
94
+ end
95
+ if opts[:onclick]
96
+ a_opts[:onclick] = opts[:onclick]
97
+ if !opts[:href]
98
+ a_opts[:href] = "#"
99
+ end
100
+ end
101
+
102
+
103
+ # process active option
104
+ if opts[:active] != nil
105
+ is_active = nil
106
+ # check to see if many conditions are specified
107
+ if opts[:active].is_a?(Array)
108
+ condition_found = false
109
+ # iterate over each
110
+ opts[:active].each do |a|
111
+ if defined?(a[:controller]) && a[:controller]
112
+ if defined?(a[:active]) && a[:active]
113
+ if process_controller_action_active_condition(a)
114
+ condition_found = true
115
+ end
116
+ else
117
+ if process_controller_active_condition(a)
118
+ condition_found = true
119
+ end
120
+ end
121
+ else
122
+ raise "Unexpected active condition"
123
+ end
124
+ end
125
+ is_active = condition_found
126
+ #logger.debug("poly_condition #{opts[:active].to_json} #{is_active.to_json}")
127
+ else
128
+ is_active = process_active_condition(opts[:active])
129
+ end
130
+
131
+ if is_active
132
+ li_opts[:class] += " active "
133
+ end
134
+ end
135
+
136
+
137
+ if li_opts[:class] == ""
138
+ li_opts.delete(:class)
139
+ end
140
+ if a_opts[:class] == ""
141
+ a_opts.delete(:class)
142
+ end
143
+
144
+ if opts[:toggle] == :none
145
+ a_opts.delete('data-toggle')
146
+ end
147
+
148
+
149
+ if content_inside_a
150
+ display_name = display_name.concat(content_inside_a)
151
+ end
152
+
153
+ a_content = content_tag_string(:a, display_name.html_safe, a_opts)
154
+ #Rails.logger.debug("a_hash #{a_opts}\t#{a_content}")
155
+ # the <a> tag goes in the <li>
156
+ li_content = a_content
157
+ if content_inside_li # is there extra stuff to throw in there?
158
+ li_content = li_content.concat(content_inside_li)
159
+ end
160
+ content_tag_string(:li, li_content, li_opts)
161
+ end
162
+
163
+ def build_drop_down_menu(dat)
164
+ if !dat
165
+ raise "No actions"
166
+ end
167
+ menu_items = ""
168
+ dat.each do |item|
169
+ display_name = if item[:label] then
170
+ item[:label]
171
+ else
172
+ item[:id] ? item[:id].to_s.titlecase : "No Name"
173
+ end
174
+ item[:dropdown] = false
175
+
176
+ menu_items.concat(tab_tag(display_name, nil, nil, item.merge({:toggle => :none})))
177
+ end
178
+ menu = content_tag_string(:ul, menu_items.html_safe, :class => "dropdown-menu")
179
+ return menu
180
+ end
181
+
182
+ #
183
+ #
184
+
185
+ def process_active_condition(option)
186
+ if option.is_a?(Array)
187
+ raise "Option shouldn't be an array"
188
+ end
189
+ if option == true || option == false
190
+ return option
191
+ else
192
+ if option[:controller] != nil
193
+ res= process_controller_action_active_condition(option)
194
+ #logger.debug("Controller condition #{option[:controller].to_s} = #{res.to_json}")
195
+ return res
196
+ end
197
+ end
198
+ raise "No controller specified"
199
+ end
200
+
201
+ def process_controller_action_active_condition(option)
202
+
203
+ controller_pass = controller_name == option[:controller].to_s
204
+ #logger.debug("Pass? #{controller_pass.to_json}")
205
+ if option[:action] != nil
206
+ return controller_pass && action_name == option[:action].to_s
207
+ else
208
+ return controller_pass
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,42 @@
1
+ module Spurs
2
+ module Nav
3
+ module Helper
4
+
5
+
6
+ # Build a navigation
7
+ # :type can be either :pills or :tabs
8
+ # :style applies to ul
9
+ def spurs_nav(options={ }, &block)
10
+
11
+ opts = Spurs::Nav::nav_default_options.merge(options)
12
+ if !opts[:builder]
13
+ raise "Null builder"
14
+ end
15
+
16
+ opts_to_pass_to_builder = {}
17
+ if opts[:dynamic]
18
+ opts_to_pass_to_builder[:dynamic] = opts[:dynamic]
19
+ end
20
+
21
+ if !opts[:type].in? [:pills,:tabs,:list]
22
+ Rails.logger.debug("WARNING: unknown spurs_nav flavor. Using tabs instead")
23
+ opts[:type] = :tabs
24
+ end
25
+
26
+ nav_builder = opts[:builder].new(opts_to_pass_to_builder)
27
+
28
+ output = capture(nav_builder, &block)
29
+
30
+ ul_args = {
31
+ :class => "nav nav-#{opts[:type]} #{opts[:stacked] ? "nav-stacked" : ""} #{opts[:class] ? opts[:class] : ""}"
32
+ }
33
+
34
+ if defined?(opts[:style]) then
35
+ ul_args[:style] = opts[:style]
36
+ end
37
+
38
+ content_tag_string(:ul, output, ul_args)
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/spurs/nav.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "spurs/nav/builder"
2
+ require "spurs/nav/helper"
3
+
4
+ module Spurs
5
+ module Nav
6
+ @@nav_default_options = {
7
+ :type => :tabs,
8
+ :builder => Spurs::Nav::Builder
9
+ }
10
+
11
+ def self.nav_default_options
12
+ @@nav_default_options
13
+ end
14
+
15
+ @@submenu_default_options= { }
16
+
17
+ def self.submenu_default_options
18
+ @@submenu_default_options
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,7 @@
1
+ module Spurs
2
+ module Popover
3
+ class Builder
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module Spurs
2
+ module Popover
3
+ module Helper
4
+
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Spurs
2
+ module Popover
3
+
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ class Spurs::Section::CollapsibleSectionBuilder
2
+ include ActionView::Helpers::TagHelper
3
+
4
+ @options_from_helper
5
+ def initialize(args={})
6
+ @options_from_helper = args.clone
7
+ end
8
+
9
+ def build_collapsible_section(title,content)
10
+ r = SecureRandom::hex(5)
11
+ section_id = "section_#{r}"
12
+
13
+
14
+ header_output = build_header(title,section_id)
15
+ body_output = build_body(content)
16
+ content_tag(:div,header_output.concat(body_output), :class => "spurs_collapsible_section #{section_id}")
17
+ end
18
+
19
+ private
20
+ def build_header(title,section_id)
21
+ header_content = build_toggle_button(section_id)
22
+ header_content.concat(content_tag(:h4,title))
23
+ content_tag(:div,header_content,:class => "section_header", :onclick => "spurs.sections.toggle($('.#{section_id}'));")
24
+ end
25
+ def build_toggle_button(section_id)
26
+ content_tag(:a, content_tag(:i,"",:class => "icon-chevron-right"), :class => "section_toggle")
27
+ end
28
+ def build_body(content)
29
+ content_tag(:div, content.html_safe, :class => "section_body")
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ module Spurs
2
+ module Section
3
+ module Helper
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ def spurs_collapsible_section(title,options={},&block)
7
+ opts = Spurs::Section::collapsible_section_default_options.merge(options)
8
+ if !opts[:builder]
9
+ raise "Null builder"
10
+ end
11
+
12
+ options_to_pass_to_builder = {}
13
+ builder = opts[:builder].new(options_to_pass_to_builder)
14
+ section_content = capture(nil,&block)
15
+ builder.build_collapsible_section(title,section_content)
16
+ end
17
+
18
+ def spurs_vcenter(options={}, &block)
19
+ opts = options.clone
20
+ if !opts[:class]
21
+ opts[:class] = ""
22
+ end
23
+ opts[:class].concat(" vcenter_outer")
24
+
25
+ # extract inner options
26
+ inner_opts = opts[:inner_html] ? opts.delete(:inner_html) : {}
27
+ if !inner_opts[:class]
28
+ inner_opts[:class] = ""
29
+ end
30
+ inner_opts[:class].concat(" inner")
31
+
32
+ section_content = capture(nil,&block)
33
+ content_tag(:div,content_tag(:div, content_tag(:div,section_content,inner_opts),:class => "middle"),opts)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ require "spurs/section/helper"
2
+ require "spurs/section/collapsible_section_builder"
3
+ module Spurs
4
+ module Section
5
+ @@collapsible_section_default_options = {
6
+ :icon_collapsed => "chevron-right",
7
+ :icon_expanded => "chevron-down",
8
+ :builder => Spurs::Section::CollapsibleSectionBuilder
9
+ }
10
+ def self.collapsible_section_default_options
11
+ @@collapsible_section_default_options
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,3 @@
1
+ module Spurs
2
+ VERSION = "0.0.1"
3
+ end
data/lib/spurs.rb ADDED
@@ -0,0 +1,26 @@
1
+
2
+ module Spurs
3
+ # Our host application root path
4
+ # We set this when the engine is initialized
5
+ mattr_accessor :app_root
6
+
7
+ # Yield self on setup for nice config blocks
8
+ def self.setup
9
+ yield self
10
+ end
11
+
12
+ end
13
+
14
+ require "spurs/modal"
15
+ require "spurs/flash"
16
+ require "spurs/nav"
17
+ require "spurs/section"
18
+ require "spurs/engine"
19
+
20
+ ActionView::Base.send :include, Spurs::Flash::Helper
21
+ ActionView::Base.send :include, Spurs::Nav::Helper
22
+ ActionView::Base.send :include, Spurs::Section::Helper
23
+ ActionView::Base.send :include, Spurs::Modal::Helper
24
+
25
+ ActionController::Base.send :include, Spurs::Flash::ControllerMods
26
+ ActionController::Base.send :include, Spurs::Modal::ControllerMods
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :spurs do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks