MobileWorkflow
Short description and motivation.
Usage
How to use my plugin.
Uploads Design
This gem includes an engine to add and process S3 attachments. The design is as follows:

Installation
Add this line to your application's Gemfile:
gem 'mobile_workflow'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mobile_workflow
Upgrade to version 0.7.7 or higher
The following utility methods have changed their parameters:
# app/models/concerns/mobile_workflow/displayable/steps/styled_content/grid.rb#20
def mw_grid_item(id: self.id, text:, detail_text: nil, preview_url: nil)
raise 'Missing id' if id.nil?
raise 'Missing text' if text.nil?
{ id: id, text: text, type: :item, detailText: detail_text, imageURL: preview_url }.compact
end
# app/models/concerns/mobile_workflow/displayable/steps/styled_content/stack.rb#20
def mw_stack_list_item(id:, text:, detail_text: nil, preview_url: nil)
raise 'Missing id' if id.nil?
raise 'Missing text' if text.nil?
{ id: id.to_s, text: text, detailText: detail_text, type: :listItem, imageURL: preview_url }.compact
end
# app/models/concerns/mobile_workflow/displayable/steps/list.rb#5
def mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, material_icon_name: nil, preview_url: nil)
{ id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name, materialIconName: material_icon_name, imageURL: preview_url }.compact
end
# app/models/concerns/mobile_workflow/displayable/steps/stack.rb#26
def mw_display_video(preview_url:, attachment_url:)
{type: :video, previewURL: preview_url, url: }
end
# app/models/concerns/mobile_workflow/displayable/steps/stack.rb#11
def mw_display_image(preview_url:, attachment_url:, content_mode: :scale_aspect_fill)
validate_content_mode!(content_mode)
{type: :image, contentMode: camelcase_converter(content_mode.to_s, first_letter: :lower), previewURL: preview_url, url: }
end
All URLs MUST now be explicitly sent as arguments to the above methods, which means they must be previously set. If not, the methods will not work.
In order to support projects using ActiveStorage, there is a new model concern MobileWorkflow::Attachable that provides a few helpers. This is what you can do to upgrade if you use ActiveStorage (otherwise the helpers must be manually created):
- Include the concern in the
ApplicationRecordclass, together withMobileWorkflow::Displayable:
class ApplicationRecord < ActiveRecord::Base
include MobileWorkflow::Attachable
include MobileWorkflow::Displayable
end
- Once included, the following helpers will be available, so use them to generate the intended URLs:
def preview_url(, options: { resize_to_fill: [200, 200] })
return nil unless .attached?
if .image?
rails_representation_url(.variant(), host: )
elsif .previewable?
rails_representation_url(.preview(), host: )
else
return nil
end
end
def ()
return nil unless .attached?
rails_blob_url(, host: )
end
Example of use:
# Old method call
mw_list_item(text: 'John Doe', detail_text: 'Company Name', image_attachment: <ActiveStorage::Attached::One>, image_url: 'https://test.org/preview')
# New method call
preview_url = preview_url(<ActiveStorage::Attached::One>, options: { resize_to_fill: [200, 200] }) || 'https://test.org/preview'
mw_list_item(text: 'John Doe', detail_text: 'Company Name', preview_url: preview_url)
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.