Skip to content
Browse files

add partials.rb for more robust partial view support

  • Loading branch information...
1 parent cafbf6c commit 9f9a6bf3692af2509e28f99d1f56b05c7d204017 @brandonmwest committed Jan 6, 2012
Showing with 80 additions and 61 deletions.
  1. +18 −0 partials.rb
  2. +2 −61 views/endpoints.haml
  3. +30 −0 views/methods.haml
  4. +30 −0 views/parameters.haml
View
18 partials.rb
@@ -0,0 +1,18 @@
+#from https://gist.github.com/119874
+module Sinatra::Partials
+ def partial(template, *args)
+ template_array = template.to_s.split('/')
+ template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ options.merge!(:layout => false)
+ locals = options[:locals] || {}
+ if collection = options.delete(:collection) then
+ collection.inject([]) do |buffer, member|
+ buffer << haml(:"#{template}", options.merge(:layout =>
+ false, :locals => {template_array[-1].to_sym => member}.merge(locals)))
+ end.join("\n")
+ else
+ haml(:"#{template}", options)
+ end
+ end
+end
View
63 views/endpoints.haml
@@ -25,64 +25,5 @@
.input
%input{:name => "name#{count}", :id => "name#{count}", :value => "#{e.name}"}
- -# should break this out into another subview
- -method_count = 0
- - e["methods"].each do |m|
- -method_count=method_count+1
- %legend
- Method: #{m.MethodName}
- %br/
- .clearfix
- %label{:for => "MethodName#{method_count}"} Method Name
- .input
- %input{:name => "MethodName#{method_count}", :id => "MethodName#{method_count}", :value => "#{m.MethodName}"}
- .clearfix
- %label{:for => "Synopsis#{method_count}"} Synopsis
- .input
- %input{:name => "Synopsis#{method_count}", :id => "Synopsis#{method_count}", :value => "#{m.Synopsis}"}
- .clearfix
- %label{:for => "HTTPMethod#{method_count}"} HTTP Method (GET, POST, PUT, etc)
- .input
- %input{:name => "HTTPMethod#{method_count}", :id => "HTTPMethod#{method_count}", :value => "#{m.HTTPMethod}"}
- .clearfix
- %label{:for => "URI#{method_count}"} URI
- .input
- %input{:name => "URI#{method_count}", :id => "URI#{method_count}", :value => "#{m.URI}"}
- .clearfix
- %label{:for => "RequiresOAuth#{method_count}"} Requires OAuth? (Y or N)
- .input
- %input{:name => "RequiresOAuth#{method_count}", :id => "RequiresOAuth#{method_count}", :value => "#{m.RequiresOAuth}"}
-
- -# and yet another subview here for all the method params
-
- -param_count = 0
- - m.parameters.each do |p|
- -param_count=param_count+1
- %legend
- Parameter: #{p.Name}
- %br/
- .clearfix
- %label{:for => "ParameterName#{param_count}"} Parameter Name
- .input
- %input{:name => "ParameterName#{param_count}", :id => "ParameterName#{param_count}", :value => "#{p.Name}"}
- .clearfix
- -#make this a textarea
- %label{:for => "Description#{param_count}"} Description
- .input
- %input{:name => "Description#{param_count}", :id => "Description#{param_count}", :value => "#{p.Description}"}
- .clearfix
- %label{:for => "Required#{param_count}"} Required? (Y or N)
- .input
- %input{:name => "Required#{param_count}", :id => "Required#{param_count}", :value => "#{p.Required}"}
- .clearfix
- %label{:for => "Default#{param_count}"} Default value
- .input
- %input{:name => "Default#{param_count}", :id => "Default#{param_count}", :value => "#{p.Default}"}
-
- -#this is where logic is needed to hide/display fields based on type
- .clearfix
- %label{:for => "Type#{param_count}"} Data type
- -#should be a dropdown
- .input
- %input{:name => "Type#{param_count}", :id => "Type#{param_count}", :value => "#{p.Type}"}
-
+ - haml :methods, :locals => {:e => e}
+
View
30 views/methods.haml
@@ -0,0 +1,30 @@
+-e.inspect
+
+-method_count = 0
+- e["methods"].each do |m|
+-method_count=method_count+1
+ %legend
+ Method: #{m.MethodName}
+ %br/
+ .clearfix
+ %label{:for => "MethodName#{method_count}"} Method Name
+ .input
+ %input{:name => "MethodName#{method_count}", :id => "MethodName#{method_count}", :value => "#{m.MethodName}"}
+ .clearfix
+ %label{:for => "Synopsis#{method_count}"} Synopsis
+ .input
+ %input{:name => "Synopsis#{method_count}", :id => "Synopsis#{method_count}", :value => "#{m.Synopsis}"}
+ .clearfix
+ %label{:for => "HTTPMethod#{method_count}"} HTTP Method (GET, POST, PUT, etc)
+ .input
+ %input{:name => "HTTPMethod#{method_count}", :id => "HTTPMethod#{method_count}", :value => "#{m.HTTPMethod}"}
+ .clearfix
+ %label{:for => "URI#{method_count}"} URI
+ .input
+ %input{:name => "URI#{method_count}", :id => "URI#{method_count}", :value => "#{m.URI}"}
+ .clearfix
+ %label{:for => "RequiresOAuth#{method_count}"} Requires OAuth? (Y or N)
+ .input
+ %input{:name => "RequiresOAuth#{method_count}", :id => "RequiresOAuth#{method_count}", :value => "#{m.RequiresOAuth}"}
+
+ - haml :parameters, :locals => {:m => m}
View
30 views/parameters.haml
@@ -0,0 +1,30 @@
+-param_count = 0
+- m.parameters.each do |p|
+-param_count=param_count+1
+ %legend
+ Parameter: #{p.Name}
+ %br/
+ .clearfix
+ %label{:for => "ParameterName#{param_count}"} Parameter Name
+ .input
+ %input{:name => "ParameterName#{param_count}", :id => "ParameterName#{param_count}", :value => "#{p.Name}"}
+ .clearfix
+ -#make this a textarea
+ %label{:for => "Description#{param_count}"} Description
+ .input
+ %input{:name => "Description#{param_count}", :id => "Description#{param_count}", :value => "#{p.Description}"}
+ .clearfix
+ %label{:for => "Required#{param_count}"} Required? (Y or N)
+ .input
+ %input{:name => "Required#{param_count}", :id => "Required#{param_count}", :value => "#{p.Required}"}
+ .clearfix
+ %label{:for => "Default#{param_count}"} Default value
+ .input
+ %input{:name => "Default#{param_count}", :id => "Default#{param_count}", :value => "#{p.Default}"}
+
+ -#this is where logic is needed to hide/display fields based on type
+ .clearfix
+ %label{:for => "Type#{param_count}"} Data type
+ -#should be a dropdown
+ .input
+ %input{:name => "Type#{param_count}", :id => "Type#{param_count}", :value => "#{p.Type}"}

0 comments on commit 9f9a6bf

Please sign in to comment.
Something went wrong with that request. Please try again.