Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy updates, README, 1 minute expiration #95

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
been viewed. This is disabled by default, but it can be set between 1 and 10
seconds
* No password is required if this field is left blank.
* Pages can be viewed multiple times. This option is off by default.

## Expiration
* If a user loses the url to find a note it will eventually expire.
Expand Down
1 change: 1 addition & 0 deletions app/models/expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def translate(text)

def expires_at
{
"1 minute" => 1.minute.from_now,
"5 minutes" => 5.minutes.from_now,
"1 hour" => 1.hour.from_now,
"1 day" => 1.day.from_now,
Expand Down
27 changes: 27 additions & 0 deletions app/presenters/page_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,39 @@ def duration_state
end
end

def sendable_message
link = Rails.application.routes.url_helpers.page_url(self)
message = "Here is a link to a onetime note"
message += " that expires in #{time_until_expiration}"
message += " ("
message += "#{expires_at.in_time_zone.strftime("%m/%d/%Y")}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/UnneededInterpolation: Prefer to_s over string interpolation.
Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.

message += " at #{expires_at.in_time_zone.strftime("%I:%M%p %Z")}."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.

message += ")"
message += " It can only be viewed once." unless multiview?
message += " "
message += link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint/UselessAssignment: Useless assignment to variable - message. Use + instead of +=.

end

def to_param
url_key
end

private

def time_until_expiration
seconds_until_expiration = expires_at - Time.current
unit = if seconds_until_expiration > 1.day
"day"
elsif seconds_until_expiration > 1.hour
"hour"
elsif seconds_until_expiration > 1.minute
"minute"
else
"second"
end
"#{(seconds_until_expiration / 1.send(unit)).round} #{unit.pluralize}"
end

def duration_error?
errors.include?(:duration)
end
Expand Down
9 changes: 7 additions & 2 deletions app/views/pages/success.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
<button>
<%= image_tag("clippy.svg", alt: "Copy to clipboard") %>
</button>
<input id="copy-text" value="<%= page_url(@page) %>">
<textarea id="copy-text" value="<%= @page.sendable_message %>"><%= @page.sendable_message %></textarea>
</div>

<p>
To view and destroy this page click <%= link_to("here", page_url(@page)) %>
<% if @page.multiview? %>
To view this page click
<% else %>
To view and destroy this page click
<% end %>
<%= link_to("here", page_url(@page)) %>
</p>
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ class Application < Rails::Application
end

config.action_controller.action_on_unpermitted_parameters = :raise
Rails.application.routes.default_url_options[:host] = ENV.fetch('HOST')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.time_zone = 'Eastern Time (US & Canada)'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

config.active_record.default_timezone = :local

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
Expand Down
6 changes: 6 additions & 0 deletions spec/presenters/page_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
expect(page_presenter.optional_fields_state).to eq("")
end
end

describe "#sendable_message" do
it 'says' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.

end
end
end