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

Add option to pass custom date and time formats #152

Closed

Conversation

gazayas
Copy link
Contributor

@gazayas gazayas commented May 14, 2022

This gives developers the option to pass a custom format to Date and DateTime partials.
Context: https://discord.com/channels/836637622432170028/836637623048601633/973728513217675354

Given a model named PartialTest with a Date attribute named date_test, we can write the following:

<td><%= render 'shared/attributes/date', attribute: :date_test, url: [:account, partial_test], date_format: "%m/%d" %></td>
<td><%= render 'shared/attributes/date_and_time', attribute: :created_at, date_format: "%m/%d", time_format: "%I %p" %></td>

This gives developers the freedom to write their own formats if they want to.

Setup

I'm having a problem with the test because Capybara isn't picking up on the changes made when overwriting the file. I'm not quite sure how to handle this one, but I thought it would be better to push some tests rather than none.

Also, we need the chronic gem which is to be pulled in via this PR. Before that gets merged in, you can check the logic by replacing the appropriate Bullet Train packages in the Gemfile, along with simply adding Chronic:

gem "chronic"
gem "bullet_train", git: "[email protected]:gazayas/bullet_train.git", branch: "features/custom-date-formats"
gem "bullet_train-themes", git: "[email protected]:bullet-train-co/bullet_train-themes.git", branch: "features/custom-date-formats"

@gazayas
Copy link
Contributor Author

gazayas commented May 14, 2022

Joint PR ← Bullet Train Base
Joint PR ← Bullet Train Themes

@jagthedrummer
Copy link
Contributor

@gazayas This looks good to me, and since the dependent PRs are already merged it seems like it should be good to go. Except for the fact that there's a merge conflict. If we can get the conflict sorted out I think we should merge this.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 3, 2023

@jagthedrummer I ended up removing the tests for the custom formats because Capybara wasn't picking up on the edited page. I originally was working with _index/html.erb but changed it to show.html.erb. Here's how I edited the file:

transformed_content = original_content.map do |line|
  if line.match?(/attribute: :date_test/)
    line.gsub(/ %>/, ", date_format: #{custom_date_format} %>")
  elsif line.match?(/attribute: :date_time_test/)
    line.gsub(/ %>/, ", date_format: #{custom_date_format}, time_format: #{custom_time_format} %>")
  else
    line
  end
end

After editing the file, running refresh to refresh the session and then visiting the show page, the changes weren't present in the test although it was working fine in the browser.

What I can do is write about the change in the docs, we just won't have tests for now.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 3, 2023

Now we just have 0 changes though, also because we added PartialTest in another PR after I opened this one... I'll write up some documentation and link it here, then close it.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 3, 2023

Just opened bullet-train-co/bullet_train-core#364, will go ahead and close this one.

@gazayas gazayas closed this Aug 3, 2023
@gazayas gazayas deleted the features/custom-date-formats branch August 3, 2023 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants