time_machine 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +27 -0
- data/app/assets/images/time_machine/calendar-disabled.png +0 -0
- data/app/assets/images/time_machine/calendar.png +0 -0
- data/app/assets/images/time_machine/metallic/calendar.png +0 -0
- data/app/assets/images/time_machine/metallic/default-date.png +0 -0
- data/app/assets/images/time_machine/metallic/disabled-date.png +0 -0
- data/app/assets/images/time_machine/metallic/header.png +0 -0
- data/app/assets/images/time_machine/metallic/selected-date.png +0 -0
- data/app/assets/images/time_machine/metallic/titles.png +0 -0
- data/app/assets/javascripts/time_machine/application.js +14 -0
- data/app/assets/javascripts/time_machine/datepicker.coffee +13 -0
- data/app/assets/javascripts/time_machine/zebra_datepicker.js +1 -0
- data/app/assets/stylesheets/time_machine/application.sass +102 -0
- data/app/assets/stylesheets/time_machine/datepicker.css +81 -0
- data/app/controllers/time_machine/application_controller.rb +17 -0
- data/app/helpers/time_machine/application_helper.rb +15 -0
- data/app/views/application/_time_machine.html.erb +13 -0
- data/config/routes.rb +3 -0
- data/lib/tasks/time_machine_tasks.rake +4 -0
- data/lib/time_machine/engine.rb +17 -0
- data/lib/time_machine/version.rb +3 -0
- data/lib/time_machine.rb +5 -0
- metadata +123 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= TimeMachine
|
2
|
+
|
3
|
+
This plugin lets you easily change Time.now.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add gem 'time_machine' to your development group and add this in a view file (ie application layout):
|
8
|
+
|
9
|
+
<%= time_machine %>
|
10
|
+
|
11
|
+
Reload, and you'll see a small box in the upper left corner of your app. Use this to travel in time and see how your app behaves/looks like when time changes.
|
12
|
+
|
13
|
+
== Options
|
14
|
+
|
15
|
+
You can pass some options to the time_machine helper to change some settings:
|
16
|
+
|
17
|
+
<%= time_machine style: 'dark', position: 'top-right', state: 'collapsed' %>
|
18
|
+
|
19
|
+
== Behind the scenes
|
20
|
+
|
21
|
+
It's just an engine with two routes. When you select a date you're sent to /time_machine/the-date where Timecop changes the date, and then you're redirected back to where you came from.
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'TimeMachine'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
jQuery ->
|
2
|
+
# initialize date picker
|
3
|
+
$('#time-machine-date').Zebra_DatePicker
|
4
|
+
always_show_clear: false
|
5
|
+
lang_clear_date: ''
|
6
|
+
onSelect: (date) -> window.location.href = "/time_machine/#{date}"
|
7
|
+
|
8
|
+
# toggle expanded/collapsed satte
|
9
|
+
$(document).on 'click', '#time-machine a.toggle', ->
|
10
|
+
$('#time-machine').toggleClass('collapsed')
|
11
|
+
false
|
12
|
+
|
13
|
+
$('#time-machine').show()
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(c){c.Zebra_DatePicker=function(F,C){var da={always_show_clear:!1,always_visible:!1,days:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),direction:0,disabled_dates:!1,first_day_of_week:1,format:"Y-m-d",inside:!0,lang_clear_date:"Clear",months:"January February March April May June July August September October November December".split(" "),offset:[20,-5],pair:!1,readonly_element:!0,show_week_number:!1,start_date:!1,view:"days",weekend_days:[0,6],onSelect:null},s,l,w, x,z,D,E,G,S,N,U,o,n,v,p,k,O,H,I,T,P,q,r,Q,J,L,X,Y,Z,y,a=this;a.settings={};var t=c(F),aa=function(b){b||(a.settings=c.extend({},da,C));a.settings.readonly_element&&t.attr("readonly","readonly");var d={days:["d","j"],months:["F","m","M","n","t"],years:["o","Y","y"]},g=!1,f=!1,h=!1;for(type in d)c.each(d[type],function(c,b){a.settings.format.indexOf(b)>-1&&(type=="days"?g=true:type=="months"?f=true:type=="years"&&(h=true))});y=g&&f&&h?["years","months","days"]:!g&&f&&h?["years","months"]:!g&&!f&&h? ["years"]:["years","months","days"];-1==c.inArray(a.settings.view,y)&&(a.settings.view=y[y.length-1]);var d=new Date,i=!a.settings.reference_date?t.data("zdp_reference_date")?t.data("zdp_reference_date"):d:a.settings.reference_date,e,j;r=q=void 0;o=i.getMonth();S=d.getMonth();n=i.getFullYear();N=d.getFullYear();v=i.getDate();U=d.getDate();if(!0===a.settings.direction)q=i;else if(!1===a.settings.direction)r=i,L=r.getMonth(),J=r.getFullYear(),Q=r.getDate();else if(!c.isArray(a.settings.direction)&& M(a.settings.direction)&&0<m(a.settings.direction)||c.isArray(a.settings.direction)&&(!0===a.settings.direction[0]||M(a.settings.direction[0])&&0<a.settings.direction[0]||(e=R(a.settings.direction[0])))&&(!1===a.settings.direction[1]||M(a.settings.direction[1])&&0<=a.settings.direction[1]||(j=R(a.settings.direction[1]))))q=e?e:new Date(n,o,v+(!c.isArray(a.settings.direction)?m(a.settings.direction):m(!0===a.settings.direction[0]?0:a.settings.direction[0]))),o=q.getMonth(),n=q.getFullYear(),v=q.getDate(), j&&+j>+q?r=j:!j&&(!1!==a.settings.direction[1]&&c.isArray(a.settings.direction))&&(r=new Date(n,o,v+m(a.settings.direction[1]))),r&&(L=r.getMonth(),J=r.getFullYear(),Q=r.getDate());else if(!c.isArray(a.settings.direction)&&M(a.settings.direction)&&0>m(a.settings.direction)||c.isArray(a.settings.direction)&&(!1===a.settings.direction[0]||M(a.settings.direction[0])&&0>a.settings.direction[0])&&(M(a.settings.direction[1])&&0<=a.settings.direction[1]||(e=R(a.settings.direction[1]))))r=new Date(n,o,v+ (!c.isArray(a.settings.direction)?m(a.settings.direction):m(!1===a.settings.direction[0]?0:a.settings.direction[0]))),L=r.getMonth(),J=r.getFullYear(),Q=r.getDate(),e&&+e<+r?q=e:!e&&c.isArray(a.settings.direction)&&(q=new Date(J,L,Q-m(a.settings.direction[1]))),q&&(o=q.getMonth(),n=q.getFullYear(),v=q.getDate());if(q&&A(n,o,v)){for(;A(n);)q?n++:n--,o=0;for(;A(n,o);)q?o++:o--,11<o?(n++,o=0):0>o&&(n--,o=0),v=1;for(;A(n,o,v);)q?v++:v--;d=new Date(n,o,v);n=d.getFullYear();o=d.getMonth();v=d.getDate()}T= [];c.each(a.settings.disabled_dates,function(){for(var a=this.split(" "),b=0;b<4;b++){a[b]||(a[b]="*");a[b]=a[b].indexOf(",")>-1?a[b].split(","):Array(a[b]);for(var d=0;d<a[b].length;d++)if(a[b][d].indexOf("-")>-1){var e=a[b][d].match(/^([0-9]+)\-([0-9]+)/);if(null!=e){for(var f=m(e[1]);f<=m(e[2]);f++)c.inArray(f,a[b])==-1&&a[b].push(f+"");a[b].splice(d,1)}}for(d=0;d<a[b].length;d++)a[b][d]=isNaN(m(a[b][d]))?a[b][d]:m(a[b][d])}T.push(a)});(e=R(t.val()||(a.settings.start_date?a.settings.start_date: "")))&&A(e.getFullYear(),e.getMonth(),e.getDate())&&t.val("");$(e);b||(a.settings.always_visible||(b='<button type="button" class="Zebra_DatePicker_Icon'+("disabled"==t.attr("disabled")?" Zebra_DatePicker_Icon_Disabled":"")+'">Pick a date</button>',w=c(b),a.icon=w,(a.settings.readonly_element?w.add(t):w).bind("click",function(b){b.preventDefault();t.attr("disabled")||(l.css("display")!="none"?a.hide():a.show())}),w.insertAfter(F),b=c(F).position(),e=c(F).outerHeight(!0),j=c(F).outerWidth(!0),icon_width= w.outerWidth(!0),icon_height=w.outerHeight(!0),a.settings.inside?(w.addClass("Zebra_DatePicker_Icon_Inside"),w.css({left:b.left+j-icon_width,top:b.top+(e-icon_height)/2})):w.css({left:b.left+j,top:b.top+(e-icon_height)/2})),b='<div class="Zebra_DatePicker"><table class="dp_header"><tr><td class="dp_previous">«</td><td class="dp_caption"> </td><td class="dp_next">»</td></tr></table><table class="dp_daypicker"></table><table class="dp_monthpicker"></table><table class="dp_yearpicker"></table><table class="dp_footer"><tr><td>'+ a.settings.lang_clear_date+"</td></tr></table></div>",l=c(b),a.datepicker=l,x=c("table.dp_header",l),z=c("table.dp_daypicker",l),D=c("table.dp_monthpicker",l),E=c("table.dp_yearpicker",l),G=c("table.dp_footer",l),a.settings.always_visible?t.attr("disabled")||(a.settings.always_visible.append(l),a.show()):c("body").append(l),l.delegate("td:not(.dp_disabled, .dp_weekend_disabled, .dp_not_in_month, .dp_blocked, .dp_week_number)","mouseover",function(){c(this).addClass("dp_hover")}).delegate("td:not(.dp_disabled, .dp_weekend_disabled, .dp_not_in_month, .dp_blocked, .dp_week_number)", "mouseout",function(){c(this).removeClass("dp_hover")}),b=c("td",x),c.browser.mozilla?b.css("MozUserSelect","none"):c.browser.msie?b.bind("selectstart",function(){return false}):b.mousedown(function(){return false}),c(".dp_previous",x).bind("click",function(){if(!c(this).hasClass("dp_blocked")){if(s=="months")k--;else if(s=="years")k=k-12;else if(--p<0){p=11;k--}K()}}),c(".dp_caption",x).bind("click",function(){s=s=="days"?c.inArray("months",y)>-1?"months":c.inArray("years",y)>-1?"years":"days":s== "months"?c.inArray("years",y)>-1?"years":c.inArray("days",y)>-1?"days":"months":c.inArray("days",y)>-1?"days":c.inArray("months",y)>-1?"months":"years";K()}),c(".dp_next",x).bind("click",function(){if(!c(this).hasClass("dp_blocked")){if(s=="months")k++;else if(s=="years")k=k+12;else if(++p==12){p=0;k++}K()}}),z.delegate("td:not(.dp_disabled, .dp_weekend_disabled, .dp_not_in_month, .dp_week_number)","click",function(){V(k,p,m(c(this).html()),"days",c(this))}),D.delegate("td:not(.dp_disabled)","click", function(){var b=c(this).attr("class").match(/dp\_month\_([0-9]+)/);p=m(b[1]);if(c.inArray("days",y)==-1)V(k,p,1,"months",c(this));else{s="days";a.settings.always_visible&&t.val("");K()}}),E.delegate("td:not(.dp_disabled)","click",function(){k=m(c(this).html());if(c.inArray("months",y)==-1)V(k,1,1,"years",c(this));else{s="months";a.settings.always_visible&&t.val("");K()}}),c("td",G).bind("click",function(b){b.preventDefault();t.val("");if(!a.settings.always_visible){k=p=I=H=O=null;G.css("display", "none")}a.hide()}),a.settings.always_visible||c(document).bind({mousedown:a._mousedown,keyup:a._keyup}),K())};a.hide=function(){a.settings.always_visible||(ba("hide"),l.css("display","none"))};a.show=function(){s=a.settings.view;var b=R(t.val()||(a.settings.start_date?a.settings.start_date:""));b?(H=b.getMonth(),p=b.getMonth(),I=b.getFullYear(),k=b.getFullYear(),O=b.getDate(),A(I,H,O)&&(t.val(""),p=o,k=n)):(p=o,k=n);K();if(a.settings.always_visible)l.css("display","block");else{var b=l.outerWidth(), d=l.outerHeight(),g=w.offset().left+a.settings.offset[0],f=w.offset().top-d+a.settings.offset[1],h=c(window).width(),i=c(window).height(),e=c(window).scrollTop(),j=c(window).scrollLeft();g+b>j+h&&(g=j+h-b);g<j&&(g=j);f+d>e+i&&(f=e+i-d);f<e&&(f=e);l.css({left:g,top:f});l.fadeIn(c.browser.msie&&c.browser.version.match(/^[6-8]/)?0:150,"linear");ba()}};a.update=function(b){a.original_direction&&(a.original_direction=a.direction);a.settings=c.extend(a.settings,b);aa(!0)};var R=function(b){b+="";if(""!= c.trim(b)){var d;d=a.settings.format.replace(/\s/g,"").replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1");for(var g="dDjlNSwFmMnYy".split(""),f=[],h=[],i=0;i<g.length;i++)-1<(position=d.indexOf(g[i]))&&f.push({character:g[i],position:position});f.sort(function(a,b){return a.position-b.position});c.each(f,function(a,b){switch(b.character){case "d":h.push("0[1-9]|[12][0-9]|3[01]");break;case "D":h.push("[a-z]{3}");break;case "j":h.push("[1-9]|[12][0-9]|3[01]");break;case "l":h.push("[a-z]+");break;case "N":h.push("[1-7]"); break;case "S":h.push("st|nd|rd|th");break;case "w":h.push("[0-6]");break;case "F":h.push("[a-z]+");break;case "m":h.push("0[1-9]|1[012]+");break;case "M":h.push("[a-z]{3}");break;case "n":h.push("[1-9]|1[012]");break;case "Y":h.push("[0-9]{4}");break;case "y":h.push("[0-9]{2}")}});if(h.length&&(f.reverse(),c.each(f,function(a,b){d=d.replace(b.character,"("+h[h.length-a-1]+")")}),h=RegExp("^"+d+"$","ig"),segments=h.exec(b.replace(/\s/g,"")))){var e,j,k,l="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "), o="January February March April May June July August September October November December".split(" "),p,n=!0;f.reverse();c.each(f,function(b,d){if(!n)return!0;switch(d.character){case "m":case "n":j=m(segments[b+1]);break;case "d":case "j":e=m(segments[b+1]);break;case "D":case "l":case "F":case "M":p="D"==d.character||"l"==d.character?a.settings.days:a.settings.months;n=!1;c.each(p,function(a,c){if(n)return!0;if(segments[b+1].toLowerCase()==c.substring(0,"D"==d.character||"M"==d.character?3:c.length).toLowerCase()){switch(d.character){case "D":segments[b+ 1]=l[a].substring(0,3);break;case "l":segments[b+1]=l[a];break;case "F":segments[b+1]=o[a];j=a+1;break;case "M":segments[b+1]=o[a].substring(0,3),j=a+1}n=!0}});break;case "Y":k=m(segments[b+1]);break;case "y":k="19"+m(segments[b+1])}});if(n&&(b=new Date(k,(j||1)-1,e||1),b.getFullYear()==k&&b.getDate()==(e||1)&&b.getMonth()==(j||1)-1))return b}return!1}},ca=function(){var b=(new Date(k,p+1,0)).getDate(),d=(new Date(k,p,1)).getDay(),g=(new Date(k,p,0)).getDate(),d=d-a.settings.first_day_of_week,d=0> d?7+d:d;W(a.settings.months[p]+", "+k);var f="<tr>";a.settings.show_week_number&&(f+="<th>"+a.settings.show_week_number+"</th>");for(var h=0;7>h;h++)f+="<th>"+a.settings.days[(a.settings.first_day_of_week+h)%7].substr(0,2)+"</th>";f+="</tr><tr>";for(h=0;42>h;h++){0<h&&0==h%7&&(f+="</tr><tr>");if(0==h%7&&a.settings.show_week_number){var i=new Date(k,p,h-d+1),e=new Date(k,0,1),j=e.getDay()-a.settings.first_day_of_week,e=Math.floor((i.getTime()-e.getTime()-6E4*(i.getTimezoneOffset()-e.getTimezoneOffset()))/ 864E5)+1,j=0<=j?j:j+7;4>j?(j=Math.floor((e+j-1)/7)+1,52<j+1&&(i.getFullYear(),i=nYear.getDay()-a.settings.first_day_of_week,i=0<=i?i:i+7,j=4>i?1:53)):j=Math.floor((e+j-1)/7);f+='<td class="dp_week_number">'+j+"</td>"}i=h-d+1;h<d?f+='<td class="dp_not_in_month">'+(g-d+h+1)+"</td>":i>b?f+='<td class="dp_not_in_month">'+(i-b)+"</td>":(j=(a.settings.first_day_of_week+h)%7,e="",A(k,p,i)?(e=-1<c.inArray(j,a.settings.weekend_days)?"dp_weekend_disabled":e+" dp_disabled",p==S&&(k==N&&U==i)&&(e+=" dp_disabled_current")): (-1<c.inArray(j,a.settings.weekend_days)&&(e="dp_weekend"),p==H&&(k==I&&O==i)&&(e+=" dp_selected"),p==S&&(k==N&&U==i)&&(e+=" dp_current")),f+="<td"+(""!=e?' class="'+c.trim(e)+'"':"")+">"+u(i,2)+"</td>")}z.html(c(f+"</tr>"));a.settings.always_visible&&(X=c("td:not(.dp_disabled, .dp_weekend_disabled, .dp_not_in_month, .dp_blocked, .dp_week_number)",z));z.css("display","")},ba=function(a){if(c.browser.msie&&c.browser.version.match(/^6/)){if(!P){var d=m(l.css("zIndex"))-1;P=jQuery("<iframe>",{src:'javascript:document.write("")', scrolling:"no",frameborder:0,allowtransparency:"true",css:{zIndex:d,position:"absolute",top:-1E3,left:-1E3,width:l.outerWidth(),height:l.outerHeight(),filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0)",display:"none"}});c("body").append(P)}switch(a){case "hide":P.css("display","none");break;default:a=l.offset(),P.css({top:a.top,left:a.left,display:"block"})}}},A=function(b,d,g){if(c.isArray(a.settings.direction)||0!==m(a.settings.direction)){var f=m(B(b,"undefined"!=typeof d?u(d,2):"","undefined"!= typeof g?u(g,2):"")),h=(f+"").length;if(8==h&&("undefined"!=typeof q&&f<m(B(n,u(o,2),u(v,2)))||"undefined"!=typeof r&&f>m(B(J,u(L,2),u(Q,2))))||6==h&&("undefined"!=typeof q&&f<m(B(n,u(o,2)))||"undefined"!=typeof r&&f>m(B(J,u(L,2))))||4==h&&("undefined"!=typeof q&&f<n||"undefined"!=typeof r&&f>J))return!0}if(T){"undefined"!=typeof d&&(d+=1);var i=!1;c.each(T,function(){if(!i&&(-1<c.inArray(b,this[2])||-1<c.inArray("*",this[2])))if("undefined"!=typeof d&&-1<c.inArray(d,this[1])||-1<c.inArray("*",this[1]))if("undefined"!= typeof g&&-1<c.inArray(g,this[0])||-1<c.inArray("*",this[0])){if("*"==this[3])return i=!0;var a=(new Date(b,d-1,g)).getDay();if(-1<c.inArray(a,this[3]))return i=!0}});if(i)return!0}return!1},M=function(a){return(a+"").match(/^\-?[0-9]+$/)?!0:!1},W=function(b){c(".dp_caption",x).html(b);if(c.isArray(a.settings.direction)||0!==m(a.settings.direction)){var b=k,d=p,g,f;"days"==s?(f=0>d-1?B(b-1,"11"):B(b,u(d-1,2)),g=11<d+1?B(b+1,"00"):B(b,u(d+1,2))):"months"==s?(f=b-1,g=b+1):"years"==s&&(f=b-7,g=b+7); A(f)?(c(".dp_previous",x).addClass("dp_blocked"),c(".dp_previous",x).removeClass("dp_hover")):c(".dp_previous",x).removeClass("dp_blocked");A(g)?(c(".dp_next",x).addClass("dp_blocked"),c(".dp_next",x).removeClass("dp_hover")):c(".dp_next",x).removeClass("dp_blocked")}},K=function(){if(""==z.text()||"days"==s){if(""==z.text()){a.settings.always_visible||l.css("left",-1E3);l.css({display:"block"});ca();var b=z.outerWidth(),d=z.outerHeight();x.css("width",b);D.css({width:b,height:d});E.css({width:b, height:d});G.css("width",b);l.css({display:"none"})}else ca();D.css("display","none");E.css("display","none")}else if("months"==s){W(k);b="<tr>";for(d=0;12>d;d++){0<d&&0==d%3&&(b+="</tr><tr>");var g="dp_month_"+d;A(k,d)?g+=" dp_disabled":!1!==H&&H==d?g+=" dp_selected":S==d&&N==k&&(g+=" dp_current");b+='<td class="'+c.trim(g)+'">'+a.settings.months[d].substr(0,3)+"</td>"}D.html(c(b+"</tr>"));a.settings.always_visible&&(Y=c("td:not(.dp_disabled)",D));D.css("display","");z.css("display","none");E.css("display", "none")}else if("years"==s){W(k-7+" - "+(k+4));b="<tr>";for(d=0;12>d;d++)0<d&&0==d%3&&(b+="</tr><tr>"),g="",A(k-7+d)?g+=" dp_disabled":I&&I==k-7+d?g+=" dp_selected":N==k-7+d&&(g+=" dp_current"),b+="<td"+(""!=c.trim(g)?' class="'+c.trim(g)+'"':"")+">"+(k-7+d)+"</td>";E.html(c(b+"</tr>"));a.settings.always_visible&&(Z=c("td:not(.dp_disabled)",E));E.css("display","");z.css("display","none");D.css("display","none")}(a.settings.always_show_clear||a.settings.always_visible||""!=t.val())&&"block"!=G.css("display")? G.css("display",""):G.css("display","none")},V=function(b,c,g,f,h){var i=new Date(b,c,g),f="days"==f?X:"months"==f?Y:Z,e;e="";for(var j=i.getDate(),l=i.getDay(),n=a.settings.days[l],m=i.getMonth()+1,o=a.settings.months[m-1],q=i.getFullYear()+"",r=0;r<a.settings.format.length;r++){var s=a.settings.format.charAt(r);switch(s){case "y":q=q.substr(2);case "Y":e+=q;break;case "m":m=u(m,2);case "n":e+=m;break;case "M":o=o.substr(0,3);case "F":e+=o;break;case "d":j=u(j,2);case "j":e+=j;break;case "D":n=n.substr(0, 3);case "l":e+=n;break;case "N":l++;case "w":e+=l;break;case "S":e=1==j%10&&"11"!=j?e+"st":2==j%10&&"12"!=j?e+"nd":3==j%10&&"13"!=j?e+"rd":e+"th";break;default:e+=s}}t.val(e);a.settings.always_visible&&(H=i.getMonth(),p=i.getMonth(),I=i.getFullYear(),k=i.getFullYear(),O=i.getDate(),f.removeClass("dp_selected"),h.addClass("dp_selected"));a.hide();$(i);if(a.settings.onSelect&&"function"==typeof a.settings.onSelect)a.settings.onSelect(e,b+"-"+u(c+1,2)+"-"+u(g,2),new Date(b,c,g))},B=function(){for(var a= "",c=0;c<arguments.length;c++)a+=arguments[c]+"";return a},u=function(a,c){for(a+="";a.length<c;)a="0"+a;return a},m=function(a){return parseInt(a,10)},$=function(b){if(a.settings.pair)if(!a.settings.pair.data||!a.settings.pair.data("Zebra_DatePicker"))a.settings.pair.data("zdp_reference_date",b);else{var c=a.settings.pair.data("Zebra_DatePicker");c.update({reference_date:b});c.settings.always_visible&&c.show()}};a._keyup=function(b){("block"==l.css("display")||27==b.which)&&a.hide();return!0};a._mousedown= function(b){if("block"==l.css("display")){if(c(b.target).get(0)===w.get(0))return!0;0==c(b.target).parents().filter(".Zebra_DatePicker").length&&a.hide()}return!0};aa()};c.fn.Zebra_DatePicker=function(F){return this.each(function(){if(void 0!=c(this).data("Zebra_DatePicker")){var C=c(this).data("Zebra_DatePicker");C.icon.remove();C.datepicker.remove();c(document).unbind("keyup",C._keyup);c(document).unbind("mousedown",C._mousedown)}C=new c.Zebra_DatePicker(this,F);c(this).data("Zebra_DatePicker", C)})}})(jQuery);
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
14
|
+
|
15
|
+
body
|
16
|
+
|
17
|
+
#time-machine
|
18
|
+
position: absolute
|
19
|
+
top: 0
|
20
|
+
padding: 6px 8px
|
21
|
+
font-family: geneva
|
22
|
+
box-shadow: #999 0px 3px 15px
|
23
|
+
width: 150px
|
24
|
+
border:
|
25
|
+
bottom: 1px solid #ccc
|
26
|
+
right: 1px solid #ccc
|
27
|
+
|
28
|
+
&.top-left
|
29
|
+
left: 0
|
30
|
+
border-bottom-right-radius: 5px
|
31
|
+
a.toggle
|
32
|
+
float: right
|
33
|
+
a.reset
|
34
|
+
float: right
|
35
|
+
|
36
|
+
&.top-right
|
37
|
+
right: 0
|
38
|
+
border-bottom-left-radius: 5px
|
39
|
+
a.reset
|
40
|
+
float: left
|
41
|
+
a.toggle
|
42
|
+
left: 0
|
43
|
+
h6
|
44
|
+
float: right
|
45
|
+
input
|
46
|
+
float: right
|
47
|
+
|
48
|
+
&.light
|
49
|
+
background: #fff
|
50
|
+
a, h6
|
51
|
+
color: #333
|
52
|
+
|
53
|
+
&.dark
|
54
|
+
background: #373737
|
55
|
+
a
|
56
|
+
color: #fae03a
|
57
|
+
h6
|
58
|
+
color: #ccc
|
59
|
+
|
60
|
+
&.collapsed
|
61
|
+
width: 15px
|
62
|
+
a.reset, input, h6
|
63
|
+
display: none
|
64
|
+
a.toggle
|
65
|
+
font-size: 18px
|
66
|
+
font-weight: bold
|
67
|
+
|
68
|
+
button
|
69
|
+
display: none
|
70
|
+
|
71
|
+
a.reset, a.toggle
|
72
|
+
text-decoration: none
|
73
|
+
font-size: 10px
|
74
|
+
|
75
|
+
a.reset
|
76
|
+
margin-top: 7px
|
77
|
+
|
78
|
+
a.toggle
|
79
|
+
position: relative
|
80
|
+
font-size: 12px
|
81
|
+
|
82
|
+
input#time-machine-date
|
83
|
+
font-family: geneva
|
84
|
+
font-size: 12px
|
85
|
+
text-shadow: #fff 0px 1px 1px
|
86
|
+
background: #fff
|
87
|
+
box-shadow: #999 0px 0px 30px inset
|
88
|
+
text-align: center
|
89
|
+
width: 105px !important
|
90
|
+
margin: 0
|
91
|
+
border: none
|
92
|
+
padding: 3px
|
93
|
+
cursor: pointer !important
|
94
|
+
|
95
|
+
h6
|
96
|
+
padding: 0
|
97
|
+
margin: 0
|
98
|
+
font-size: 12px
|
99
|
+
letter-spacing: 3px
|
100
|
+
font-weight: normal
|
101
|
+
text-transform: uppercase
|
102
|
+
text-shadow: #000 0px 0px 6px
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Zebra_DatePicker: a lightweight jQuery date picker plugin
|
4
|
+
|
5
|
+
default stylesheet
|
6
|
+
copyright (c) 2011 - 2012 Stefan Gabos
|
7
|
+
http://stefangabos.ro/jquery/zebra-datepicker/
|
8
|
+
|
9
|
+
*/
|
10
|
+
|
11
|
+
.Zebra_DatePicker * { margin: 0; padding: 0; color: #666 }
|
12
|
+
.Zebra_DatePicker { position: absolute; background: #373737; border: 3px solid #373737; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; display: none; z-index: 100; font-family: Geneva, 'Lucida Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif; font-size: 11px }
|
13
|
+
|
14
|
+
/* = GLOBALS
|
15
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
16
|
+
.Zebra_DatePicker table { width: 100%; border-collapse: collapse; border-spacing: 0 }
|
17
|
+
|
18
|
+
.Zebra_DatePicker td,
|
19
|
+
.Zebra_DatePicker th { text-align: center; padding: 5px 0 }
|
20
|
+
|
21
|
+
.Zebra_DatePicker td { cursor: pointer }
|
22
|
+
|
23
|
+
.Zebra_DatePicker .dp_daypicker,
|
24
|
+
.Zebra_DatePicker .dp_monthpicker,
|
25
|
+
.Zebra_DatePicker .dp_yearpicker { margin-top: 3px }
|
26
|
+
|
27
|
+
.Zebra_DatePicker .dp_daypicker td,
|
28
|
+
.Zebra_DatePicker .dp_daypicker th,
|
29
|
+
.Zebra_DatePicker .dp_monthpicker td,
|
30
|
+
.Zebra_DatePicker .dp_yearpicker td { width: 30px; border: 1px solid #BBB; background: #DEDEDE url('metallic/default-date.png') repeat-x top; color: #666 }
|
31
|
+
|
32
|
+
/* = HEADER
|
33
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
34
|
+
.Zebra_DatePicker .dp_header td { color: #E0E0E0; background: #373737 }
|
35
|
+
|
36
|
+
.Zebra_DatePicker .dp_header .dp_previous,
|
37
|
+
.Zebra_DatePicker .dp_header .dp_next { width: 30px }
|
38
|
+
|
39
|
+
.Zebra_DatePicker .dp_header .dp_caption { font-weight: bold }
|
40
|
+
.Zebra_DatePicker .dp_header .dp_hover { background: #222; color: #FFF; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px }
|
41
|
+
.Zebra_DatePicker .dp_header .dp_blocked { color: #888; cursor: default }
|
42
|
+
|
43
|
+
/* = DATEPICKER
|
44
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
45
|
+
.Zebra_DatePicker td.dp_week_number,
|
46
|
+
.Zebra_DatePicker .dp_daypicker th { background: #F1F1F1 url('metallic/titles.png') repeat-x top; font-size: 9px; padding-top: 7px }
|
47
|
+
|
48
|
+
.Zebra_DatePicker td.dp_weekend_disabled,
|
49
|
+
.Zebra_DatePicker td.dp_not_in_month { background: #ECECEC url('metallic/disabled-date.png'); color: #DDD; cursor: default }
|
50
|
+
|
51
|
+
.Zebra_DatePicker td.dp_weekend { background: #DEDEDE url('metallic/default-date.png') repeat-x top; color: #666 }
|
52
|
+
|
53
|
+
.Zebra_DatePicker td.dp_selected { background: #E26262 url('metallic/selected-date.png') repeat-x top; color: #E0E0E0 }
|
54
|
+
|
55
|
+
/* = MONTHPICKER
|
56
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
57
|
+
.Zebra_DatePicker .dp_monthpicker td { width: 33% }
|
58
|
+
|
59
|
+
/* = YEARPICKER
|
60
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
61
|
+
.Zebra_DatePicker .dp_yearpicker td { width: 33% }
|
62
|
+
|
63
|
+
/* = SOME MORE GLOBALS (MUST BE LAST IN ORDER TO OVERWRITE PRESIOUS PROPERTIES)
|
64
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
65
|
+
.Zebra_DatePicker td.dp_current { color: #E26261 }
|
66
|
+
.Zebra_DatePicker td.dp_disabled_current { color: #E38585 }
|
67
|
+
.Zebra_DatePicker td.dp_hover { background: #E26262 url('metallic/selected-date.png') repeat-x top; color: #E0E0E0 }
|
68
|
+
.Zebra_DatePicker td.dp_disabled { background: #ECECEC url('metallic/disabled-date.png') repeat-x top; color: #DDD; cursor: default }
|
69
|
+
|
70
|
+
/* = ICON
|
71
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
72
|
+
/* = ICON
|
73
|
+
----------------------------------------------------------------------------------------------------------------------*/
|
74
|
+
button.Zebra_DatePicker_Icon { position: absolute; width: 16px; height: 16px; background: url('calendar.png') no-repeat left top; text-indent: -9000px; border: none; cursor: pointer; margin: 0 0 0 5px; padding: 0; line-height: 0 }
|
75
|
+
button.Zebra_DatePicker_Icon_Disabled { background-image: url('calendar-disabled.png') }
|
76
|
+
button.Zebra_DatePicker_Icon_Inside { margin: 0 0 0 2px }
|
77
|
+
|
78
|
+
/* Fix icon position in Chrome & Safari */
|
79
|
+
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
80
|
+
button.Zebra_DatePicker_Icon_Inside { margin: 0 5px 0 0 }
|
81
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TimeMachine
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
|
4
|
+
def reset
|
5
|
+
Timecop.return
|
6
|
+
redirect_to params[:redirect] || :back
|
7
|
+
end
|
8
|
+
|
9
|
+
def travel
|
10
|
+
date = Date.parse params[:date]
|
11
|
+
Timecop.travel date
|
12
|
+
redirect_to params[:redirect] || :back
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TimeMachine
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
def time_machine(options={})
|
5
|
+
options = {
|
6
|
+
style: 'light',
|
7
|
+
position: 'top-left',
|
8
|
+
state: 'expanded',
|
9
|
+
}.update options
|
10
|
+
|
11
|
+
options[:classes] = options.select { |k,v| [:position, :style, :state].include? k }.values.join " "
|
12
|
+
render :partial => 'time_machine', locals: { options: options }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div class="<%= options[:classes] %>" style="position: absolute; top: 0; left: -100000; display: none" id="time-machine" >
|
2
|
+
<%= link_to "¤", "#", class: 'toggle' %>
|
3
|
+
<h6>Timemachine</h6>
|
4
|
+
<input value="<%= Time.now.strftime('%Y-%m-%d') %>" type="text" readonly="readonly" id="time-machine-date"/>
|
5
|
+
<%= link_to "reset", "/time_machine/reset", class: 'reset' %>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(function() {
|
10
|
+
$("head").append($("<link rel='stylesheet' href='/assets/time_machine/application.css' type='text/css' media='screen' />"));
|
11
|
+
$("head").append($("<script type='text/javascript' src='/assets/time_machine/application.js' type='text/css' media='screen' />"));
|
12
|
+
});
|
13
|
+
</script>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module TimeMachine
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace TimeMachine
|
4
|
+
|
5
|
+
config.to_prepare do
|
6
|
+
::ApplicationController.helper(TimeMachine::ApplicationHelper)
|
7
|
+
end
|
8
|
+
|
9
|
+
config.after_initialize do |app|
|
10
|
+
app.routes.append do
|
11
|
+
get '/time_machine/reset' => 'time_machine/application#reset'
|
12
|
+
get '/time_machine/:date' => 'time_machine/application#travel'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/time_machine.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: time_machine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gudleik Rasch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.8
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jquery-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: timecop
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Development tool for changing Time.now in your rails app
|
63
|
+
email:
|
64
|
+
- gudleik@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- app/assets/images/time_machine/calendar-disabled.png
|
70
|
+
- app/assets/images/time_machine/calendar.png
|
71
|
+
- app/assets/images/time_machine/metallic/calendar.png
|
72
|
+
- app/assets/images/time_machine/metallic/default-date.png
|
73
|
+
- app/assets/images/time_machine/metallic/disabled-date.png
|
74
|
+
- app/assets/images/time_machine/metallic/header.png
|
75
|
+
- app/assets/images/time_machine/metallic/selected-date.png
|
76
|
+
- app/assets/images/time_machine/metallic/titles.png
|
77
|
+
- app/assets/javascripts/time_machine/application.js
|
78
|
+
- app/assets/javascripts/time_machine/datepicker.coffee
|
79
|
+
- app/assets/javascripts/time_machine/zebra_datepicker.js
|
80
|
+
- app/assets/stylesheets/time_machine/application.sass
|
81
|
+
- app/assets/stylesheets/time_machine/datepicker.css
|
82
|
+
- app/controllers/time_machine/application_controller.rb
|
83
|
+
- app/helpers/time_machine/application_helper.rb
|
84
|
+
- app/views/application/_time_machine.html.erb
|
85
|
+
- config/routes.rb
|
86
|
+
- lib/tasks/time_machine_tasks.rake
|
87
|
+
- lib/time_machine/engine.rb
|
88
|
+
- lib/time_machine/version.rb
|
89
|
+
- lib/time_machine.rb
|
90
|
+
- MIT-LICENSE
|
91
|
+
- Rakefile
|
92
|
+
- README.rdoc
|
93
|
+
homepage: https://github.com/gudleik/time_machine
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: -4077653272273999823
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -4077653272273999823
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.23
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Provides timetravelling in your rails app
|
123
|
+
test_files: []
|