diff --git a/README b/README new file mode 100644 index 0000000..09bd675 --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +This is the base layout and utilities I'm using right now for many of +my sites. You're welcome to use it as you wish. + +Credits, suggestions and complaints: + + send to: Norman Clarke diff --git a/base_site_generator.rb b/base_site_generator.rb new file mode 100644 index 0000000..56388bc --- /dev/null +++ b/base_site_generator.rb @@ -0,0 +1,20 @@ +class BaseSiteGenerator < Rails::Generator::Base + def manifest + record do |m| + m.file "config/initializers/application_config.rb", "config/initializers/application_config.rb" + m.file "config/application.yml", "config/application.yml" + m.file "app/helpers/application_helper.rb", "app/helpers/application_helper.rb" + m.directory "app/views/common" + m.file "app/views/common/403.html.erb", "app/views/common/403.html.erb" + m.file "app/views/common/404.html.erb", "app/views/common/404.html.erb" + m.file "app/views/common/_analytics.html.erb", "app/views/common/_analytics.html.erb" + m.file "app/views/common/_flash.html.erb", "app/views/common/_flash.html.erb" + m.file "app/views/common/_footer.html.erb", "app/views/common/_footer.html.erb" + m.file "app/views/common/_head.html.erb", "app/views/common/_head.html.erb" + m.file "app/views/common/_navigation.html.erb", "app/views/common/_navigation.html.erb" + m.file "public/stylesheets/main.css", "public/stylesheets/main.css" + m.file "public/stylesheets/print.css", "public/stylesheets/print.css" + m.file "public/stylesheets/reset.css", "public/stylesheets/reset.css" + end + end +end diff --git a/templates/app/helpers/application_helper.rb b/templates/app/helpers/application_helper.rb new file mode 100644 index 0000000..0893777 --- /dev/null +++ b/templates/app/helpers/application_helper.rb @@ -0,0 +1,29 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper + + def body_class + "#{controller.controller_name}_#{controller.action_name}" + end + + def content_exists(name) + instance_variable_defined?("@content_for_#{name.to_s}") + end + + def page_header(text) + content_for :page_header do + content_tag(:h2, text) + end + end + + def page_title(text) + content_for :page_title do + text + end + end + + def page_title_or_header + text = @content_for_page_title || @content_for_page_header || '' + strip_tags(text) + (text.include?(APP_CONFIG["site_name"]) ? '' : " - #{APP_CONFIG["site_name"]}") + end + +end diff --git a/templates/app/views/common/403.html.erb b/templates/app/views/common/403.html.erb new file mode 100644 index 0000000..9df69df --- /dev/null +++ b/templates/app/views/common/403.html.erb @@ -0,0 +1,11 @@ +<% page_header "Permission Error" %> +<% content_for :main do %> +

+ The link that you just clicked, or the form you submitted, has led you to + a part of the site that we didn't intend for you to see. For the + technically minded, this is a "403" error. +

+<% end %> +<% content_for :side do %> + <%= link_to_function "Go back", "history.go(-1)", :class => "back" %> +<% end %> \ No newline at end of file diff --git a/templates/app/views/common/404.html.erb b/templates/app/views/common/404.html.erb new file mode 100644 index 0000000..8c3850e --- /dev/null +++ b/templates/app/views/common/404.html.erb @@ -0,0 +1,11 @@ +<% page_header "Error - Not Found" %> +<% content_for :main do %> +

+ The link that you just clicked, or the form you submitted, has led you to a + url that we don't have any content for. For the technically minded, this + is a "404" error. +

+<% end %> +<% content_for :side do %> + <%= link_to_function "Go back", "history.go(-1)", :class => "back" %> +<% end %> \ No newline at end of file diff --git a/templates/app/views/common/_analytics.html.erb b/templates/app/views/common/_analytics.html.erb new file mode 100644 index 0000000..595cbe7 --- /dev/null +++ b/templates/app/views/common/_analytics.html.erb @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/templates/app/views/common/_flash.html.erb b/templates/app/views/common/_flash.html.erb new file mode 100644 index 0000000..646cd6f --- /dev/null +++ b/templates/app/views/common/_flash.html.erb @@ -0,0 +1,10 @@ +
+ <% unless flash.empty? -%> + <%= content_tag :div, flash[:notice], :id => "flash_message", :class => "notice" if flash[:notice] -%> + <%= content_tag :div, flash[:warning], :id => "flash_message", :class => "warning" if flash[:warning] -%> + <%= content_tag :div, flash[:error], :id => "flash_message", :class => "error" if flash[:error] -%> + + <% end -%> +
diff --git a/templates/app/views/common/_footer.html.erb b/templates/app/views/common/_footer.html.erb new file mode 100644 index 0000000..0d49fe2 --- /dev/null +++ b/templates/app/views/common/_footer.html.erb @@ -0,0 +1,9 @@ + +<%= render :partial => "common/analytics" if RAILS_ENV == "production" %> diff --git a/templates/app/views/common/_head.html.erb b/templates/app/views/common/_head.html.erb new file mode 100644 index 0000000..8ca2b72 --- /dev/null +++ b/templates/app/views/common/_head.html.erb @@ -0,0 +1,14 @@ + + + + +<%= page_title_or_header -%> +<%= stylesheet_link_tag 'reset', 'main', :media => "screen", :cache => "screen" %> +<%= stylesheet_link_tag 'print', :media => "print" %> + +<%= javascript_include_tag :all, :cache => true %> diff --git a/templates/app/views/common/_navigation.html.erb b/templates/app/views/common/_navigation.html.erb new file mode 100644 index 0000000..cc8bbeb --- /dev/null +++ b/templates/app/views/common/_navigation.html.erb @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/templates/app/views/layouts/main.html.erb b/templates/app/views/layouts/main.html.erb new file mode 100644 index 0000000..2ab4f0f --- /dev/null +++ b/templates/app/views/layouts/main.html.erb @@ -0,0 +1,38 @@ + + + + <% if content_exists :head %> + <% yield :head %> + <% else -%> + <%= render :partial => "common/head" %> + <% end -%> + + <% content_tag :body, :class => body_class, :onload => @onload do %> + <% content_tag :div, :id => "wrapper" do %> + <% content_tag :div, :id => "all_content_wrapper" do %> + <%= content_tag :h1, link_to(APP_CONFIG["site_name"], root_url) %> + <% content_tag :div, :id => "page_content_wrapper", :class => "clearfix" do %> + <% content_tag :div, :id => "main_content_wrapper" do %> + <%= yield :page_header %> + <%= render :partial => "common/flash", :locals => {:flash => flash} %> + <%= yield :main %> + <% end %> + <% content_tag :div, :id => "side_content_wrapper" do %> + <%= yield :side %> + <% end %> + <% end -%> + <% if content_exists :navigation -%> + <%= yield :navigation %> + <% else -%> + <%= render :partial => "common/navigation" %> + <% end -%> + <% if content_exists :footer -%> + <%= yield :footer %> + <% else -%> + <%= render :partial => "common/footer" %> + <% end -%> + <% end %> + <% end %> + <% end %> + \ No newline at end of file diff --git a/templates/config/application.yml b/templates/config/application.yml new file mode 100644 index 0000000..7a34a51 --- /dev/null +++ b/templates/config/application.yml @@ -0,0 +1,12 @@ +development: &non_production_settings + host: 0.0.0.0:3000 + site_name: "My Site" + +test: + <<: *non_production_settings + +production: + host: example.org + site_name: "My Site" + # your analytics id code here (e.g. UA-11111111-11) + google_analytics_id: "" \ No newline at end of file diff --git a/templates/config/initializers/application_config.rb b/templates/config/initializers/application_config.rb new file mode 100644 index 0000000..ef25a89 --- /dev/null +++ b/templates/config/initializers/application_config.rb @@ -0,0 +1,3 @@ +APP_CONFIG = YAML.load(File.read(RAILS_ROOT + "/config/application.yml"))[RAILS_ENV] +# This will let you more easily use helpers based on url_for in your mailers. +ActionMailer::Base.default_url_options[:host] = APP_CONFIG['host'] \ No newline at end of file diff --git a/templates/public/stylesheets/main.css b/templates/public/stylesheets/main.css new file mode 100644 index 0000000..5e4988b --- /dev/null +++ b/templates/public/stylesheets/main.css @@ -0,0 +1,45 @@ +/* base html defaults */ +html, body { font-family: "arial", sans-serif; line-height: 1.2em; + background-color: #f0f0f0; font-size: 95% } +hr { display: none;} +p { margin: 0 0 10px 0;} +ul { margin: 0 0 20px 0;} +h1, h2, h3, h4, h5, h6 { font-family: "lucida grande", trebuchet, sans-serif; font-weight: bold; margin: 0 0 10px 0;} +h2 { font-size: 120%; margin: 0 0 20px 0; } +h3 { font-size: 100%; margin: 0 0 10px; } +fieldset { margin-bottom: 20px;} +legend { padding-bottom: 10px; } +blockquote { width: 50%; margin: auto; font-style: italic; } +h1 { position: absolute; top: 20px; font-size: 100%; font-family: "lucida grande", sans-serif; + padding: 0 0 0 1px;} +img.avatar { padding: 2px; border: 1px #c0c0c0 double; } +a img, h2 img { vertical-align: middle; } +textarea { font-family: arial, sans-serif;} +h1 a, h1 a:visited, #navigation a { color: blue; text-decoration: none;} +h1 a, a.app, #navigation a:visited { color: blue; text-decoration: none; } +input[type=text], input[type=password], textarea { font-size: 18px; + border: 1px #d0d0d0 inset; } +select { border: 1px #d0d0d0 inset; } + +/* core utilities */ +.clearfix:after { content: "."; display: block; height: 0; clear: both; + visibility: hidden; } + +/* core layout */ +#flash_message { margin-bottom: 10px;} +#all_content_wrapper { width: 800px; margin: auto; position: relative; padding-top: 50px; } +#page_content_wrapper { border: 1px #f0f0f0 solid; background-color: #fff; padding: 10px 0 10px 0;} +#main_content_wrapper { width: 577px; margin: 0 0 0 0; padding: 0 10px 10px 10px; float: left; } +#side_content_wrapper { width: 170px; margin: 0; padding: 0 10px 0 10px; float: left; } +ul#navigation { padding: 0 1px 0 0; } +#navigation li { display: inline; margin-left: 5px; } +#navigation { position: absolute; top: 20px; right: 0; height: 30px; line-height: 30px;} +#footer { margin: 10px 0 0 0; color: #c0c0c0; font-style: italic; font-size: 90%; + text-align: right;} +#footer a { color: #c0c0c0; } +div.pagination { display: block; padding: 10px 0 10px 0; margin: 10px 0 10px 0; } +div.pagination { color: #707070; font-size: .9em; text-align: right; } +#side_content_wrapper ul, #side_content_wrapper p { font-size: .9em;} +#side_content_wrapper li { margin: 2px 0 2px 0; } + +.meta { color: #707070; font-size: small; } \ No newline at end of file diff --git a/templates/public/stylesheets/print.css b/templates/public/stylesheets/print.css new file mode 100644 index 0000000..de2d631 --- /dev/null +++ b/templates/public/stylesheets/print.css @@ -0,0 +1 @@ +#navigation { display: none; } \ No newline at end of file diff --git a/templates/public/stylesheets/reset.css b/templates/public/stylesheets/reset.css new file mode 100644 index 0000000..c1d296d --- /dev/null +++ b/templates/public/stylesheets/reset.css @@ -0,0 +1,10 @@ +:link,:visited { text-decoration:none } +ul,ol { list-style:none } +h1,h2,h3,h4,h5,h6,pre,code { font-size:1em; font-weight: normal; } +ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset +{ margin:0; padding:0; border: none; } +input { margin: 0; padding: 0;} +a { outline-style:none; } +a img,:link img,:visited img { border:none } +address { font-style:normal } +br, div.clearer {float: none; clear: both;} \ No newline at end of file