From dd00734e1192a3c8acf1314388c113248c469926 Mon Sep 17 00:00:00 2001 From: kaboo Date: Thu, 5 Sep 2013 22:06:25 +0200 Subject: [PATCH 1/5] create template solution --- app/assets/javascripts/application.js | 12 +++++++++++ app/assets/stylesheets/main.css.sass | 6 ++++++ app/controllers/pages_controller.rb | 14 +++++++------ app/helpers/pages_helper.rb | 17 +++++++++++++++ app/views/pages/_country.html.erb | 2 ++ app/views/pages/about.html.erb | 10 +-------- app/views/pages/africa.html.erb | 11 +--------- app/views/pages/asia.html.erb | 11 +--------- app/views/pages/australia.html.erb | 11 +--------- app/views/pages/country.html.erb | 2 -- app/views/pages/country.js.erb | 2 ++ app/views/pages/europe.html.erb | 13 ++---------- app/views/pages/home.html.erb | 21 ++++++++++++------- app/views/pages/north_america.html.erb | 11 +--------- app/views/pages/south_america.html.erb | 11 +--------- ...0905182512_add_coordinates_to_countries.rb | 5 +++++ 16 files changed, 73 insertions(+), 86 deletions(-) create mode 100644 app/assets/stylesheets/main.css.sass create mode 100644 app/views/pages/_country.html.erb delete mode 100644 app/views/pages/country.html.erb create mode 100644 app/views/pages/country.js.erb create mode 100644 db/migrate/20130905182512_add_coordinates_to_countries.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index fb3f248..33399b4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,9 +14,21 @@ //= require jquery_ujs //= require_tree . + +jQuery.fn.center = function () { + this.css("position","absolute"); + this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + + $(window).scrollTop()) + "px"); + this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + + $(window).scrollLeft()) + "px"); + return this; +}; + $(document).ready(function(){ $('#c_nav li').click(function() { $(this).siblings('li').removeClass('active'); $(this).addClass('active'); }); + + $("#country-info").center(); }); \ No newline at end of file diff --git a/app/assets/stylesheets/main.css.sass b/app/assets/stylesheets/main.css.sass new file mode 100644 index 0000000..f91cec6 --- /dev/null +++ b/app/assets/stylesheets/main.css.sass @@ -0,0 +1,6 @@ +#country-info + position: absolute + z-index: 99 + width: 200px + height: 100px + background-color: white \ No newline at end of file diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 051b83e..4254c6b 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,26 +3,28 @@ def home end def country + @country = Country.where(name: params[:name]).first + #render "country.js.erb", as: "JS" end def about end - + def north_america end - + def south_america end - + def europe end - + def africa end - + def asia end - + def australia end end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 2c057fd..63766b1 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -1,2 +1,19 @@ module PagesHelper + + def map_area country + ret = <<-HTML + + HTML + ret.html_safe + end + + def map_link country + link_to country.name, pages_country_path(country.name), remote: true, id: country.name + end + + def shape coords + coords.split(",").size == 4 ? "rect" : "poly" + end + end diff --git a/app/views/pages/_country.html.erb b/app/views/pages/_country.html.erb new file mode 100644 index 0000000..d58205d --- /dev/null +++ b/app/views/pages/_country.html.erb @@ -0,0 +1,2 @@ +<%= @country.name %>
+<%= link_to "close", "#", onclick: "$('#country-info').hide();return false" %> diff --git a/app/views/pages/about.html.erb b/app/views/pages/about.html.erb index 1506f0e..9eb43d0 100644 --- a/app/views/pages/about.html.erb +++ b/app/views/pages/about.html.erb @@ -1,10 +1,2 @@ <% provide(:title, 'About') %> - - - - World | <%= yield(:title) %> - - -

World

- - +about omg, nie doctype, to uz mas v layouts/application.html nadefinovane \ No newline at end of file diff --git a/app/views/pages/africa.html.erb b/app/views/pages/africa.html.erb index 34b5b77..e76eb5f 100644 --- a/app/views/pages/africa.html.erb +++ b/app/views/pages/africa.html.erb @@ -1,11 +1,2 @@ <% provide(:title, 'Home') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/app/views/pages/asia.html.erb b/app/views/pages/asia.html.erb index 34b5b77..e76eb5f 100644 --- a/app/views/pages/asia.html.erb +++ b/app/views/pages/asia.html.erb @@ -1,11 +1,2 @@ <% provide(:title, 'Home') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/app/views/pages/australia.html.erb b/app/views/pages/australia.html.erb index 34b5b77..e76eb5f 100644 --- a/app/views/pages/australia.html.erb +++ b/app/views/pages/australia.html.erb @@ -1,11 +1,2 @@ <% provide(:title, 'Home') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/app/views/pages/country.html.erb b/app/views/pages/country.html.erb deleted file mode 100644 index 261e2c3..0000000 --- a/app/views/pages/country.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Pages#country

-

Find me in app/views/pages/country.html.erb

diff --git a/app/views/pages/country.js.erb b/app/views/pages/country.js.erb new file mode 100644 index 0000000..95499b0 --- /dev/null +++ b/app/views/pages/country.js.erb @@ -0,0 +1,2 @@ +$("#country-info").html('<%= escape_javascript(render "country") %>'); +$("#country-info").show(); \ No newline at end of file diff --git a/app/views/pages/europe.html.erb b/app/views/pages/europe.html.erb index 6f82e6e..e76eb5f 100644 --- a/app/views/pages/europe.html.erb +++ b/app/views/pages/europe.html.erb @@ -1,11 +1,2 @@ -<% provide(:title, 'Europe') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +<% provide(:title, 'Home') %> +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index 34b5b77..278e1af 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -1,11 +1,16 @@ <% provide(:title, 'Home') %> <%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - \ No newline at end of file + <% @countries.each do |country| %> + <%= map_area country %> + <% end %> + + + + + \ No newline at end of file diff --git a/app/views/pages/north_america.html.erb b/app/views/pages/north_america.html.erb index 34b5b77..e76eb5f 100644 --- a/app/views/pages/north_america.html.erb +++ b/app/views/pages/north_america.html.erb @@ -1,11 +1,2 @@ <% provide(:title, 'Home') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/app/views/pages/south_america.html.erb b/app/views/pages/south_america.html.erb index 34b5b77..e76eb5f 100644 --- a/app/views/pages/south_america.html.erb +++ b/app/views/pages/south_america.html.erb @@ -1,11 +1,2 @@ <% provide(:title, 'Home') %> -<%= image_tag("Misc_Map_400645.jpg", :usemap => "#map") %> - - - - - - - - - \ No newline at end of file +WTF, PRECO JE VSADE TO ISTE OMG!!!! \ No newline at end of file diff --git a/db/migrate/20130905182512_add_coordinates_to_countries.rb b/db/migrate/20130905182512_add_coordinates_to_countries.rb new file mode 100644 index 0000000..ba527b1 --- /dev/null +++ b/db/migrate/20130905182512_add_coordinates_to_countries.rb @@ -0,0 +1,5 @@ +class AddCoordinatesToCountries < ActiveRecord::Migration + def change + add_column :countries, :coordinates, :string + end +end From fb0245ad8352d65d68436ea4d35a02ad60a7f581 Mon Sep 17 00:00:00 2001 From: kaboo Date: Thu, 5 Sep 2013 22:49:55 +0200 Subject: [PATCH 2/5] move migration to other pull request --- db/migrate/20130905182512_add_coordinates_to_countries.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/migrate/20130905182512_add_coordinates_to_countries.rb diff --git a/db/migrate/20130905182512_add_coordinates_to_countries.rb b/db/migrate/20130905182512_add_coordinates_to_countries.rb deleted file mode 100644 index ba527b1..0000000 --- a/db/migrate/20130905182512_add_coordinates_to_countries.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCoordinatesToCountries < ActiveRecord::Migration - def change - add_column :countries, :coordinates, :string - end -end From 8f16f7725941586813032eb7c2a13a4e5fd7dd66 Mon Sep 17 00:00:00 2001 From: kaboo Date: Tue, 10 Sep 2013 20:15:19 +0200 Subject: [PATCH 3/5] polish the code a little --- app/assets/javascripts/application.js | 19 --------------- app/assets/javascripts/pages.js | 17 +++++++++++++ app/assets/javascripts/pages.js.coffee | 3 --- app/controllers/pages_controller.rb | 1 - app/helpers/application_helper.rb | 10 ++++++++ app/helpers/pages_helper.rb | 8 ++----- app/views/layouts/_continents_navbar.html.erb | 24 +++++++++---------- app/views/pages/home.html.erb | 7 +----- 8 files changed, 42 insertions(+), 47 deletions(-) create mode 100644 app/assets/javascripts/pages.js delete mode 100644 app/assets/javascripts/pages.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 33399b4..9097d83 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,22 +13,3 @@ //= require jquery //= require jquery_ujs //= require_tree . - - -jQuery.fn.center = function () { - this.css("position","absolute"); - this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + - $(window).scrollTop()) + "px"); - this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + - $(window).scrollLeft()) + "px"); - return this; -}; - -$(document).ready(function(){ - $('#c_nav li').click(function() { - $(this).siblings('li').removeClass('active'); - $(this).addClass('active'); - }); - - $("#country-info").center(); -}); \ No newline at end of file diff --git a/app/assets/javascripts/pages.js b/app/assets/javascripts/pages.js new file mode 100644 index 0000000..c499c2a --- /dev/null +++ b/app/assets/javascripts/pages.js @@ -0,0 +1,17 @@ +$(document).ready(function(){ + + $(".country-area").click(function(e) { + var top = e.pageY + "px"; + var left = e.pageX + "px"; + $("#country-info").css({top: top, left: left}); + }); + +}); + +function show_country(name) { + $.ajax({ + url: "/country", + data: "name=" + name, + dataType: 'script' + }); +} diff --git a/app/assets/javascripts/pages.js.coffee b/app/assets/javascripts/pages.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/pages.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4254c6b..5bacec4 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -4,7 +4,6 @@ def home def country @country = Country.where(name: params[:name]).first - #render "country.js.erb", as: "JS" end def about diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..f596bf8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,12 @@ module ApplicationHelper + + def nav_link text, action + s = <<-HTML +
  • + #{link_to text, send("pages_#{action}_path")} +
  • + HTML + s.html_safe + end + end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 63766b1..1591363 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -2,16 +2,12 @@ module PagesHelper def map_area country ret = <<-HTML - + HTML ret.html_safe end - def map_link country - link_to country.name, pages_country_path(country.name), remote: true, id: country.name - end - def shape coords coords.split(",").size == 4 ? "rect" : "poly" end diff --git a/app/views/layouts/_continents_navbar.html.erb b/app/views/layouts/_continents_navbar.html.erb index bd4467e..3607f72 100644 --- a/app/views/layouts/_continents_navbar.html.erb +++ b/app/views/layouts/_continents_navbar.html.erb @@ -1,15 +1,15 @@ -