-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'features/layout_console_helper'
- Loading branch information
Showing
8 changed files
with
69 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
module TimecopConsole | ||
module MainHelper | ||
def time_travel_to(date) | ||
def time_travel_to(date, name = nil) | ||
unless date.respond_to?(:year) && date.respond_to?(:month) && date.respond_to?(:day) | ||
raise ArgumentError, "Argument must be a Date object" | ||
end | ||
|
||
name ||= date.strftime("%B %d, %Y") | ||
hour = date.respond_to?(:hour) ? date.hour : 12 | ||
min = date.respond_to?(:min) ? date.min : 0 | ||
|
||
update_path = timecop_console.update_path(timecop: { | ||
'current_time(1i)' => date.year, | ||
'current_time(2i)' => date.month, | ||
'current_time(3i)' => date.day, | ||
'current_time(4i)' => 12, | ||
'current_time(5i)' => 0 | ||
'current_time(4i)' => hour, | ||
'current_time(5i)' => min | ||
}) | ||
|
||
button_to(date.strftime("%B %d, %Y"), | ||
update_path, | ||
method: :post) | ||
button_to(name, update_path) | ||
end | ||
|
||
def timecop_console_layout | ||
render partial: 'timecop_console/console_layout', layout: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div id="timecop-console"> | ||
<p> | ||
<%= Time.now.strftime("Current time is: %D %r") %> | ||
</p> | ||
<%= form_tag timecop_console.update_path do %> | ||
<p> | ||
<%= datetime_select("timecop", "current_time") %> | ||
</p> | ||
<p> | ||
<%= submit_tag "Time Travel", :class => 'btn' %> | ||
</p> | ||
<% end %> | ||
<%= link_to "Reset", timecop_console.reset_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
<h1>TimeCopConsole Demo</h1> | ||
<p>Hello world!</p> | ||
<p> | ||
The time is now | ||
<%= Time.now %> | ||
</p> | ||
|
||
<%= time_travel_to(Date.parse("December 31, 1999")) %> | ||
<%= link_to "Reset Time", timecop_console.reset_path %> | ||
<%= timecop_console_layout %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters