Permalink
Browse files

Switched to Slim

  • Loading branch information...
1 parent 4901fc0 commit 9d611e8bef064879ea70b5a9b77cdeedc442f791 @DanielVartanov committed Nov 21, 2011
Showing with 90 additions and 26 deletions.
  1. +1 −1 Gemfile
  2. +8 −5 Gemfile.lock
  3. +3 −2 application.rb
  4. +60 −0 public/map.js
  5. 0 views/{index.haml → index.slim}
  6. +0 −18 views/layout.haml
  7. +18 −0 views/layout.slim
View
2 Gemfile
@@ -1,4 +1,4 @@
source :rubygems
gem "sinatra"
-gem "haml"
+gem "slim"
View
13 Gemfile.lock
@@ -1,19 +1,22 @@
GEM
remote: http://rubygems.org/
specs:
- haml (3.1.3)
rack (1.3.5)
rack-protection (1.1.4)
rack
sinatra (1.3.1)
- rack (>= 1.3.4, ~> 1.3)
- rack-protection (>= 1.1.2, ~> 1.1)
- tilt (>= 1.3.3, ~> 1.3)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ slim (1.0.4)
+ temple (~> 0.3.4)
+ tilt (~> 1.3.2)
+ temple (0.3.4)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
- haml
sinatra
+ slim
View
5 application.rb
@@ -1,7 +1,8 @@
require "sinatra"
-require "haml"
+require "slim"
set :public_folder, File.dirname(__FILE__) + '/public'
+Slim::Engine.set_default_options :pretty => true
def price(distance)
distance < 2 ?
@@ -10,7 +11,7 @@ def price(distance)
end
get '/' do
- haml :index
+ slim :index
end
get '/:distance' do
View
60 public/map.js
@@ -0,0 +1,60 @@
+var map;
+var route = new Array();
+
+var directionsService;
+var directionsDisplay;
+
+function initialize() {
+ var latlng = new google.maps.LatLng(42.830022, 74.587883);
+ var myOptions = {
+ zoom: 13,
+ center: latlng,
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+ map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
+
+ directionsService = new google.maps.DirectionsService();
+ directionsDisplay = new google.maps.DirectionsRenderer();
+ directionsDisplay.setMap(map);
+
+ google.maps.event.addListener(map, 'click', function(event) {
+ point = event.latLng
+ route.push(point);
+ placeMarker(point);
+
+ if (route.length >= 2) {
+ drawRoute();
+ }
+ });
+}
+
+function drawRoute() {
+ var request = {
+ origin: route[0],
+ destination: route[1],
+ travelMode: google.maps.DirectionsTravelMode.DRIVING
+ };
+
+ directionsService.route(request, function(response, status) {
+ if (status == google.maps.DirectionsStatus.OK) {
+ var leg = response.routes[0].legs[0];
+ directionsDisplay.setDirections(response);
+ calculateRouteCost(leg.distance.value);
+ }
+ });
+}
+
+function placeMarker(location) {
+ var marker = new google.maps.Marker({
+ position: location,
+ map: map
+ });
+}
+
+function calculateRouteCost(distance) {
+ var request = new XMLHttpRequest();
+ request.open("GET", distance / 1000, false);
+ request.send(null);
+ alert(request.responseText);
+ return distance;
+}
View
0 views/index.haml → views/index.slim
File renamed without changes.
View
18 views/layout.haml
@@ -1,18 +0,0 @@
-!!! 5
-%html
- %head
- %title Сервис «Кайсы такси?». Показывает лучшее такси для выбранного маршрута.
- %meta{name:"viewport", content:"width=device-width, initial-scale=1.0, user-scalable=no"}
- %meta(charset="utf-8")
- :css
- html, body, #map_canvas {
- margin: 0;
- padding: 0;
- height: 100%;
- }
- %script{type:"text/javascript", src:"http://maps.googleapis.com/maps/api/js?sensor=false"}
- %script{type:"text/javascript", src:"map.js"}
-
- %body{onload:"initialize()"}
- #map_canvas
- = yield
View
18 views/layout.slim
@@ -0,0 +1,18 @@
+doctype 5
+html
+ head
+ title Сервис «Кайсы такси?». Показывает лучшее такси для выбранного маршрута.
+ meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"
+ meta charset="utf-8"
+ css:
+ html, body, #map_canvas {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+ }
+ script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"
+ script type="text/javascript" src="map.js"
+
+ body onload="initialize()"
+ #map_canvas
+ == yield

0 comments on commit 9d611e8

Please sign in to comment.