summaryrefslogtreecommitdiff
path: root/lib/generators/nifty/layout/templates
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators/nifty/layout/templates')
-rw-r--r--lib/generators/nifty/layout/templates/error_messages_helper.rb23
-rw-r--r--lib/generators/nifty/layout/templates/layout.html.haml21
-rw-r--r--lib/generators/nifty/layout/templates/layout_helper.rb38
-rw-r--r--lib/generators/nifty/layout/templates/stylesheet.css83
-rw-r--r--lib/generators/nifty/layout/templates/stylesheet.sass73
5 files changed, 238 insertions, 0 deletions
diff --git a/lib/generators/nifty/layout/templates/error_messages_helper.rb b/lib/generators/nifty/layout/templates/error_messages_helper.rb
new file mode 100644
index 0000000..8e9c4d3
--- /dev/null
+++ b/lib/generators/nifty/layout/templates/error_messages_helper.rb
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
+ content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
diff --git a/lib/generators/nifty/layout/templates/layout.html.haml b/lib/generators/nifty/layout/templates/layout.html.haml
new file mode 100644
index 0000000..24ec1d6
--- /dev/null
+++ b/lib/generators/nifty/layout/templates/layout.html.haml
@@ -0,0 +1,21 @@
+!!!
+%html
+
+ %head
+ %title
+ = content_for?(:title) ? yield(:title) : "Untitled"
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
+ = stylesheet_link_tag "application"
+ = javascript_include_tag "application"
+ = csrf_meta_tag
+ = yield(:head)
+
+ %body
+ #container
+ - flash.each do |name, msg|
+ = content_tag :div, msg, :id => "flash_#{name}"
+
+ - if show_title?
+ %h1= yield(:title)
+
+ = yield
diff --git a/lib/generators/nifty/layout/templates/layout_helper.rb b/lib/generators/nifty/layout/templates/layout_helper.rb
new file mode 100644
index 0000000..93011d6
--- /dev/null
+++ b/lib/generators/nifty/layout/templates/layout_helper.rb
@@ -0,0 +1,38 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+
+ def title(page_title, show_title = true)
+ content_for(:title) { strip_tags(page_title.to_s) }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+
+ def translation_missing?(output)
+ (output =~ /span/ or output.empty?)
+ end
+
+ def conditional_hint(translation_key)
+ output = t(translation_key)
+ return output unless translation_missing?(output)
+ false
+ end
+
+ def conditional_t(translation_key)
+ output = t(translation_key)
+ strip_tags(output)
+ end
+end \ No newline at end of file
diff --git a/lib/generators/nifty/layout/templates/stylesheet.css b/lib/generators/nifty/layout/templates/stylesheet.css
new file mode 100644
index 0000000..448a53f
--- /dev/null
+++ b/lib/generators/nifty/layout/templates/stylesheet.css
@@ -0,0 +1,83 @@
+html, body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+.error_messages ul {
+ margin: 0;
+}
+
+.field_with_errors {
+ display: inline;
+}
+
+form .field, form .actions {
+ margin: 10px 0;
+}
+
+form label {
+ display: block;
+}
diff --git a/lib/generators/nifty/layout/templates/stylesheet.sass b/lib/generators/nifty/layout/templates/stylesheet.sass
new file mode 100644
index 0000000..383bfd3
--- /dev/null
+++ b/lib/generators/nifty/layout/templates/stylesheet.sass
@@ -0,0 +1,73 @@
+$primary_color: #4b7399
+
+body
+ background-color: $primary_color
+ font:
+ family: Verdana, Helvetica, Arial
+ size: 14px
+
+a
+ color: blue
+ img
+ border: none
+
+.clear
+ clear: both
+ height: 0
+ overflow: hidden
+
+#container
+ width: 75%
+ margin: 0 auto
+ background: white
+ padding: 20px 40px
+ border: solid 1px black
+ margin-top: 20px
+
+#flash_notice,
+#flash_error,
+#flash_alert
+ padding: 5px 8px
+ margin: 10px 0
+
+#flash_notice
+ background-color: #ccffcc
+ border: solid 1px #66cc66
+
+#flash_error,
+#flash_alert
+ background-color: #ffcccc
+ border: solid 1px #cc6666
+
+.error_messages
+ width: 400px
+ border: 2px solid #cf0000
+ padding: 0
+ padding-bottom: 12px
+ margin-bottom: 20px
+ background-color: #f0f0f0
+ font:
+ size: 12px
+ h2
+ text-align: left
+ padding: 5px 5px 5px 15px
+ margin: 0
+ font:
+ weight: bold
+ size: 12px
+ background-color: #cc0000
+ color: white
+ p
+ margin: 8px 10px
+ ul
+ margin: 0
+
+.field_with_errors
+ display: inline
+
+form .field,
+form .actions
+ margin: 10px 0
+
+form label
+ display: block