From 9b8afba9cf7f6e511109e58e7093300aabab8754 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Thu, 12 Jan 2012 19:41:39 -0800 Subject: [PATCH] metaprogram template addition --- app/views/layouts/_templates.haml | 5 +++++ app/views/layouts/application.html.haml | 2 +- app/views/templates/_templates.haml | 18 ------------------ app/views/templates/reshare_feedback.jst | 0 .../app/views/reshare_feedback_view.js | 5 ++--- .../jasmine_fixtures/template_spec.rb | 2 +- 6 files changed, 9 insertions(+), 23 deletions(-) create mode 100644 app/views/layouts/_templates.haml delete mode 100644 app/views/templates/_templates.haml create mode 100644 app/views/templates/reshare_feedback.jst diff --git a/app/views/layouts/_templates.haml b/app/views/layouts/_templates.haml new file mode 100644 index 000000000..e70fa914e --- /dev/null +++ b/app/views/layouts/_templates.haml @@ -0,0 +1,5 @@ +- templates_dir = Rails.root.join("app", "views", "templates") += Dir[templates_dir.to_s + "/*.jst"].each do |template| + - template_name = File.basename(template, ".jst").gsub("_","-") + %script{:id => "#{template_name}-template", :type => 'text/template'} + != File.read(templates_dir.join(template)) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 376dd0e6a..6a5d085bf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -113,7 +113,7 @@ %header = render 'layouts/header' - = render 'templates/templates' + = render 'layouts/templates' .container{:style=> "#{yield(:break_the_mold)}"} - if @aspsect == :getting_started || @page == :logged_out diff --git a/app/views/templates/_templates.haml b/app/views/templates/_templates.haml deleted file mode 100644 index db497c8e2..000000000 --- a/app/views/templates/_templates.haml +++ /dev/null @@ -1,18 +0,0 @@ --# Copyright (c) 2010-2011, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -- ["header", - "feedback", - "static_text", - "stream_element", - "comment_stream", - "comment", - "status_message", - "activity_streams_photo", - "reshare", - "likes_info", - "stream_faces"].each do |template_name| - - %script{:id => "#{template_name.gsub("_","-")}-template", :type => 'text/template'} - != File.read("#{Rails.root}/app/views/templates/#{template_name}.jst") diff --git a/app/views/templates/reshare_feedback.jst b/app/views/templates/reshare_feedback.jst new file mode 100644 index 000000000..e69de29bb diff --git a/public/javascripts/app/views/reshare_feedback_view.js b/public/javascripts/app/views/reshare_feedback_view.js index 0da8de2f9..44744f9ed 100644 --- a/public/javascripts/app/views/reshare_feedback_view.js +++ b/public/javascripts/app/views/reshare_feedback_view.js @@ -1,4 +1,3 @@ -app.views.ReshareFeedback = Backbone.View.extend({ - - +app.views.ReshareFeedback = app.views.Base.extend({ + template_name: "#reshare-feedback-template", }); diff --git a/spec/controllers/jasmine_fixtures/template_spec.rb b/spec/controllers/jasmine_fixtures/template_spec.rb index fd38163a2..1743c4f52 100644 --- a/spec/controllers/jasmine_fixtures/template_spec.rb +++ b/spec/controllers/jasmine_fixtures/template_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" describe "template generation" do it "generates templates", :fixture => true do extend JasmineFixtureGeneration - templates = Haml::Engine.new(Rails.root.join("app", "views", "templates", "_templates.haml").read).render + templates = Haml::Engine.new(Rails.root.join("app", "views", "layouts", "_templates.haml").read).render save_fixture(templates, "underscore_templates") end end