Permalink
Browse files

Merge pull request #11 from jhbabon/9-mustache

Intregration of the mustache system.
  • Loading branch information...
2 parents 7feda9d + 1a2d072 commit 605a32162cc682a292dd338eb1444e23f16446fd @juanignaciosl juanignaciosl committed May 6, 2012
View
@@ -60,3 +60,7 @@ gem 'simple_form'
# better urls
gem 'friendly_id'
+
+# mustache integration
+gem 'mustache'
+gem 'stache'
View
@@ -73,6 +73,7 @@ GEM
mocha (0.11.3)
metaclass (~> 0.0.1)
multi_json (1.3.4)
+ mustache (0.99.4)
orm_adapter (0.0.7)
pg (0.13.2)
polyglot (0.3.3)
@@ -116,6 +117,8 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ stache (0.2.2)
+ mustache
subexec (0.2.2)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
@@ -148,12 +151,14 @@ DEPENDENCIES
kaminari
mini_magick
mocha
+ mustache
pg
rails (~> 3.2.3)
rails-i18n
rake
sass-rails (~> 3.2.3)
simple_form
+ stache
therubyracer
uglifier (>= 1.0.3)
unicorn
@@ -12,3 +12,10 @@
//
//= require jquery
//= require jquery_ujs
+//= require bootstrap-datepicker/bootstrap-datepicker
+//= require_self
+
+$(document).ready(function() {
+ alert('loaded');
+ $('.datepicker').datepicker();
+});
@@ -9,6 +9,7 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
+ *= require bootstrap-datepicker/datepicker
*/
/* Import bootstrap to be able to use variables and mixins */
@@ -3,6 +3,8 @@
class BackendController < ActionController::Base
layout 'backend'
+ append_view_path 'app/templates'
+
protect_from_forgery
before_filter :authenticate_user!
@@ -20,6 +20,7 @@ def show_title(&block)
capture(&block) if show_title?
end
+ # TODO: delete
def page_title
content_for?(:title) ? content_for(:title) : 'Untitled'
end
@@ -0,0 +1,39 @@
+<!doctype html>
+<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
+<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
+<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
+<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
+<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="{{ current_locale }}"> <!--<![endif]-->
+ <head>
+ <meta charset="utf-8">
+
+ <title>{{ page_title }}</title>
+ <meta name="description" content="{{ meta_description }}">
+
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ {{& stylesheets }}
+ {{& csrf_meta_tags }}
+
+ <!-- TODO: consider to add modernizr -->
+ </head>
+
+ <body>
+
+ {{& backend_navbar }}
+
+ <div class="container">
+ {{& backend_tabs }}
+ {{& backend_page_title }}
+
+ {{& yield }}
+
+ <footer class="footer row">
+ </footer>
+ </div>
+
+ <!-- NOTE: allways load the javascript at the bottom of the page -->
+ {{& javascripts }}
+ </body>
+</htm
@@ -1,52 +0,0 @@
-<!doctype html>
-<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
-<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
-<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
-<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
-<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
-<!--[if gt IE 8]><!--> <html class="no-js" lang="<%= current_locale %>"> <!--<![endif]-->
- <head>
- <meta charset="utf-8">
-
- <title><%= page_title %></title>
- <meta name="description" content="<%= meta_description %>">
-
- <%# NOTE: responsive design %>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
- <%= stylesheet_link_tag 'backend', media: 'all' %>
- <%= csrf_meta_tags %>
-
- <%# TODO: consider to add modernizr %>
- <%# javascript_include_tag "modernizr" %>
-
- <%= stylesheet_link_tag 'bootstrap-datepicker/datepicker' %>
- </head>
-
- <body>
-
- <%= backend_navbar %>
-
-
- <div class="container">
- <%= backend_tabs %>
- <%= backend_page_title %>
-
- <%= yield %>
-
- <footer class="footer row">
- </footer>
- </div>
-
- <%# NOTE: allways load the javascript at the bottom of the page %>
- <%= javascript_include_tag 'backend' %>
-
- <%= javascript_include_tag 'bootstrap-datepicker/bootstrap-datepicker' %>
-
- <script type="text/Javascript">
- $(document).ready( function() {
- $('.datepicker').datepicker();
- });
- </script>
- </body>
-</htm
@@ -0,0 +1,11 @@
+# -*- encoding: utf-8 -*-
+
+module Layouts
+ class Backend < Canvas::Layout
+ assets do |pool|
+ pool.add :stylesheet, 'backend', media: 'all'
+ pool.add :javascript, 'backend'
+ end
+ end
+end
+
@@ -0,0 +1,6 @@
+# Be sure to install mustache gem and include mustache gem in project Gemfile.
+
+# Template Handler
+require 'stache'
+# Generator
+Rails.application.config.generators.template_engine :mustache
View
@@ -0,0 +1,13 @@
+# -*- encoding: utf-8 -*-
+
+require 'mustache'
+require 'stache'
+
+require 'canvas/callbacks'
+require 'canvas/assets'
+require 'canvas/view'
+require 'canvas/layout'
+
+module Canvas
+end
+
View
@@ -0,0 +1,31 @@
+# -*- encoding: utf-8 -*-
+
+module Canvas
+ class Assets
+ attr_accessor :view
+
+ def initialize(template)
+ @view = template
+ @stylesheets = ''
+ @javascripts = ''
+ end
+
+ def add(asset_type, *options)
+ send asset_type, *options
+ end
+
+ def stylesheet(*options)
+ view.content_for(:stylesheets) { view.stylesheet_link_tag(*options) }
+ end
+
+ def javascript(*options)
+ view.content_for(:javascripts) { view.javascript_include_tag(*options) }
+ end
+
+ def render(asset_type = :stylesheets)
+ view.content_for?(asset_type) ? view.content_for(asset_type) : ''
+ end
+ alias_method :to_s, :render
+ end
+end
+
View
@@ -0,0 +1,35 @@
+# -*- encoding: utf-8 -*-
+
+module Canvas
+ module Callbacks
+ def self.included(base)
+ base.class_eval do
+ class << self
+ def _callbacks
+ @_callbacks ||= Hash.new { |h, k| h[k] = [Proc.new {}, []] }
+ end
+ protected :_callbacks
+
+ def _register_callback(name, block, *arguments)
+ _callbacks[name] = [block, arguments]
+ end
+ protected :_register_callback
+ end
+
+ def _execute_callback(name, *arguments)
+ block, extra = _registered_callbacks[name]
+ arguments = arguments + extra
+
+ instance_exec *arguments, &block
+ end
+ protected :_execute_callback
+
+ def _registered_callbacks
+ @_registered_callbacks ||= self.class.send :_callbacks
+ end
+ protected :_registered_callbacks
+ end
+ end
+ end
+end
+
View
@@ -0,0 +1,11 @@
+# -*- encoding: utf-8 -*-
+
+module Canvas
+ class Layout < ::Canvas::View
+ # TODO: add i18n
+ def page_title
+ view.content_for?(:title) ? view.content_for(:title) : 'Untitled'
+ end
+ end
+end
+
View
@@ -0,0 +1,62 @@
+# -*- encoding: utf-8 -*-
+
+module Canvas
+ class View < ::Stache::View
+ include ::Canvas::Callbacks
+
+ class << self
+ def assets(&block)
+ _register_callback(:assets, block)
+ end
+
+ def title(txt = '', &block)
+ titler = Proc.new do |text, blk|
+ _title = ''
+ if text.present?
+ _title = text
+ elsif blk
+ _title = instance_exec &blk
+ end
+
+ view.content_for(:title) { view.send(:h, _title.to_s) }
+ end
+
+ _register_callback(:title, titler, txt, block)
+ end
+ end
+
+ def render(*)
+ _setup # get ready for the render party
+ super
+ end
+
+ def _setup
+ _execute_callback(:title)
+ end
+
+ def title
+ _execute_callback(:title) unless view.content_for?(:title)
+
+ view.content_for(:title)
+ end
+
+ [:stylesheets, :javascripts].each do |asset_type|
+ define_method(asset_type) do
+ assets.render asset_type
+ end
+ end
+
+ def assets
+ @assets ||= _setup_assets
+ end
+
+ def _setup_assets
+ _assets = ::Canvas::Assets.new(view)
+ _execute_callback(:assets, _assets)
+
+ _assets
+ end
+ protected :_setup_assets
+ end
+end
+
Oops, something went wrong.

0 comments on commit 605a321

Please sign in to comment.