Permalink
Browse files

Support new lines under ECTjs

  • Loading branch information...
1 parent 02dce24 commit 3e55cb0f601b7dcacd5891c6bc2d0ad49114ea23 @kuba-kubula kuba-kubula committed Jan 29, 2013
Showing with 26 additions and 11 deletions.
  1. +11 −5 php.html
  2. +15 −6 ruby.html
View
@@ -1,20 +1,26 @@
<section name="php" class="php">
<p class="ioDesc">Request</p>
- <pre class="incoming"><code class="language-php"><% headerFirst = true %><%= "<?php" %>
+ <pre class="incoming"><code class="language-php"><% headerFirst = true %><%= "<?php\n" %>
<% eos = "<<<EOT\n" %>
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "<%= @apiUrl %><%= @url %>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
<% if @method is 'POST': %>
curl_setopt($ch, CURLOPT_POST, TRUE);
-<% end %><% if @method isnt 'GET' and @method isnt 'POST': %>
+<% end %>
+<% if @method isnt 'GET' and @method isnt 'POST': %>
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "<%= @method %>");
-<% end %><% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
+<% end %>
+<% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
$fields = <%= eos %><%= "#{line}\n" for line in @body %>EOT;
-curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);<% else if @body and @body.length > 0: %>curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);<% end %>
+curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
+<% else if @body and @body.length > 0: %>
+curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);
+<% end %>
<% if @headers and @helpers.isNotEmpty(@headers): %>curl_setopt($ch, CURLOPT_HTTPHEADER, array(<% for header, value of @headers: %><% if headerFirst: %><% headerFirst = false %><% else: %>, <% end %><%= @helpers.escape "#{header}: #{value}" %><% end %>));
-<% end %>$response = curl_exec($ch);
+<% end %>
+$response = curl_exec($ch);
curl_close($ch);
var_dump($response);</code></pre>
View
@@ -2,11 +2,20 @@
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-ruby">require 'rubygems'
require 'rest_client'
-<% if @body and @contentType is "application/x-www-form-urlencoded": %>values = CGI::escape(<%= @helpers.escape @body %>)
-<% else if @body and @contentType is "application/json": %>values = <%= @helpers.escape @body %>
-<% else if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>values = <%= @helpers.escape @body %>
-<% else if @body and @body: %>values = <%= @helpers.escape @body %>
-<% end %><% if @helpers.isNotEmpty @headers: %>headers = {<%= [':'+@helpers.rubyKey header+' => '+@helpers.escape value for header,value of @headers] %>}
-<% end %>response = RestClient.<%= @method.toLowerCase() %> "<%= @apiUrl %><%= @url %>"<% if @body: %>, values<% end %><% if @helpers.isNotEmpty @headers: %>, headers<% end %>
+<% if @body and @contentType is "application/x-www-form-urlencoded": %>
+values = CGI::escape(<%= @helpers.escape @body %>)
+<% else if @body and @contentType is "application/json": %>
+values = <%= @helpers.escape @body %>
+<% else if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
+values = <%= @helpers.escape @body %>
+<% else if @body and @body: %>
+values = <%= @helpers.escape @body %>
+<% end %>
+<% if @helpers.isNotEmpty @headers: %>
+headers = {<%= [':'+@helpers.rubyKey header+' => '+@helpers.escape value for header,value of @headers] %>}
+<% end %>
+
+response = RestClient.<%= @method.toLowerCase() %> "<%= @apiUrl %><%= @url %>"<% if @body: %>, values<% end %><% if @helpers.isNotEmpty @headers: %>, headers<% end %>
+
puts response</code></pre>
</section>

0 comments on commit 3e55cb0

Please sign in to comment.