Skip to content

Releases: Purple-Magic/tramway

0.4.2.1

01 Mar 23:26
Compare
Choose a tag to compare

Author:

Code-review:

Fix normalizes apply_to_nil argument.

What's Changed

Full Changelog: 0.4.2...0.4.2.1

0.4.2

21 Feb 23:41
Compare
Choose a tag to compare

Author:

Code-review:

What's changed basically?

Rails 7.1 provided us with a new feature in ActiveRecord normalizes.

Useful article about

Here we added almost the same feature to Tramway Form

What's changed for tramway drivers?

Example

Before

class UserForm < Tramway::BaseForm
  properties :email
  
  def email=(value)
    object.email = value.strip.downcase
  end
end

After

class UserForm < Tramway::BaseForm
  properties :email
  
  normalizes :email, with: ->(value) { value.strip.downcase }
end

It also supports arguments:

  • apply_to_nil: by default is false. Defined normalization are not applied to nil values.
  • multiple attributes normalizes :first_name, :last_name, with: ->(value) { value.strip }
  • Inheritance. Tramway Form inherits normalizations from its ancestors

It does not support:

  • object-level normalize_attribute method
  • class-level normalize method

What's Changed

Full Changelog: 0.4.1...0.4.2

0.4.1

05 Feb 12:13
Compare
Choose a tag to compare

Author:

Code-review:

What's changed for tramway drivers?

Before

class UserForm < Tramway::BaseForm
  properties :email, :password
end

class AdminForm < UserForm
  properties :permissions
end

AdminForm.properties # returns [:permissions]

After

class UserForm < Tramway::BaseForm
  properties :email, :password
end

class AdminForm < UserForm
  properties :permissions
end

AdminForm.properties # returns [:email, :password, :permissions]

What's Changed

Full Changelog: 0.4...0.4.1

0.4

20 Jan 11:15
Compare
Choose a tag to compare
0.4

Author:

Code-review:

What's changed for tramway drivers?

To use tailwind-styled pagination

Gemfile

gem 'tramway'
gem 'kaminari'

config/initializers/tramway.rb

Tramway.configure do |config|
  config.pagination = { enabled: true } # enabled is false by default
end

app/views/users/index.html.haml

= paginate @users # it will render tailwind-styled pagination buttons by default

Pagination buttons look like this

Pull Requests

Full Changelog: 0.3.2...0.4

0.3.2

04 Jan 11:09
Compare
Choose a tag to compare

Author:

Code-review:

What's Changed for Tramway Drivers?

Tailwind-styled select

Before

= tramway_form_for object, :resource do |f|
  = f.select attribute, []

returned default select

After

It returns tailwind-styled select tag.

Decorates all descendants of ActiveRecord::Relation class

Before

tramway_decorate user.posts

returned the error There is no Post::ActiveRecord_Associations_CollectionProxyDecorator class

AND

tramway_decorate user.posts.order(id: :desc)

returned the error There is no Post::ActiveRecord_AssociationRelationDecorator class

After

tramway_decorate user.posts

AND

tramway_decorate user.posts.order(id: :desc)

both return an array of PostDecorator objects.

Delegate Primary Key to Tramway Form

Before

@user_form = tramway_form User.find(params[:id])
@user_form.id # returns "NoMethodError `id`"

After

@user_form = tramway_form User.find(params[:id])
@user_form.id # returns user-id

Full Changelog: 0.3.1.2...0.3.2

0.3.1.2

23 Dec 12:31
Compare
Choose a tag to compare

What's changed for tramway drivers?

Before

user = nil
UserDecorator.decorate user # => UserDecorator#object

After

user = nil
UserDecorator.decorate user # => nil

0.3.1.1

01 Dec 15:24
Compare
Choose a tag to compare

Author:

Code-review:

What's Changed, in General?

  • Improved handling of non-existent attributes during saving.

What's Changed for Tramway Drivers?

Before the Change

class UserForm < Tramway::BaseForm
  properties :email, :name
end

# Assuming params = { email: '[email protected]' }
# Note: `name` is not included in the `params`

user_form = UserForm.new user
user_form.submit params

user.reload
user.name # Returns nil

# The issue: `first_name` gets updated even though it's not present in `params`

After the Change

  • name will no longer be updated if it is not included in the params.

0.3.1

28 Oct 00:41
Compare
Choose a tag to compare

Author:

Code-review:

What's changed basically?

Now we have 2 more helpers

  • tramway_form_for that renders Tailwind-styled form by default

What's changed for tramway drivers?

Before

= form_for object, :resource, builder: SomeBuilderThatProvidesTailwindStyles do |f|
  -# code
  = submit_button class: 'a.lot.of.tailwind.classes.here'

After

We have Tailwind-styled form helpers

= tramway_form_for object, :resource do |f|
  = f.text_field :text
  = f.password_field :password
  = f.file_field :file
  = f.submit 'Create'

Find more info here

0.3

04 Sep 23:17
Compare
Choose a tag to compare
0.3

Author:

Code-review:

What's changed basically?

Presenting useful and convenient form objects for Rails applications.

*app/forms/user_form.rb

class UserForm < Tramway::BaseForm
  properties :email, :password

  def password=(value)
    object.password = value if value.present?
  end
end

What's changed for tramway drivers?

Before

app/controllers/users_controller.rb

class UsersController < ApplicationController
  def create
    @user = User.new

    if @user.save user_params
      render :show
    else
      render :new
    end
  end

  def update
    @user = User.find params[:id]

    if @user.save user_params
      render :show
    else
      render :edit
    end
  end
  
  private

  def user_params
    params[:user].permit!
  end
end

After

app/controllers/users_controller.rb

class UsersController < ApplicationController
  def create
    @user = tramway_form User.new

    if @user.submit params[:user]
      render :show
    else
      render :new
    end
  end

  def update
    @user = tramway_form User.find params[:id]

    if @user.submit params[:user]
      render :show
    else
      render :edit
    end
  end
end

Find more info here

0.2.3

17 Aug 10:54
Compare
Choose a tag to compare

Author:

Code-review:

What's changed basically?

  • Tramway Entity route option

What's changed for tramway drivers?

Before

config/initializers/tramway.rb

Tramway.configure do |config|
  config.entities = [ :user, :podcast, :episode ]
end

After

Define entities with options

Tramway Entity supports several options that are used in different features.

route

Tramway.configure do |config|
  config.entities = [
    { name: :user, route: { namespace: :admin } },                                 # `admin_users_path` link in the Tramway Navbar
    { name: :podcast, route: { route_method: :shows } },                           # `shows_path` link in the Tramway Navbar
    { name: :episodes, route: { namespace: :podcasts, route_method: :episodes } }, # `podcasts_episodes_path` link in the Tramway Navbar
  ]
end

Find more info here