Module: Liquid::Simplero::Filters
- Includes:
- GroupingFilters
- Defined in:
- app/models/liquid/simplero/filters.rb
Constant Summary collapse
- RESPONSIVE_IMAGE_QUERIES =
Order is important
{ xl4: '(min-width: 1600px) ', xl3: '(min-width: 1366px) ', xl2: '(min-width: 1280px) ', xl: '(min-width: 1024px) ', l: '(min-width: 768px) ', m: '(min-width: 480px) ', s: '' }
Instance Method Summary collapse
-
#add_to_cart_link(product, options = {}) ⇒ Object
Generates HTML for an 'Add to cart' link for the given product.
-
#address_html(object, sep = nil) ⇒ Object
Returns HTML for the passed object's address.
-
#asset_url(file) ⇒ Object
Returns the URL for a file in the theme's
assets
directory. - #button_color_attrs(color) ⇒ Object deprecated Deprecated.
- #bytes_to_gb(bytes) ⇒ Object
- #dasherize(s) ⇒ Object deprecated Deprecated.
-
#date_only(d) ⇒ Object
Returns the formatted date portion of the passed date/time in the page's language.
-
#datetime(date_time, options = {}) ⇒ Object
Returns the formatted date and time of the passed date/time in the page's language.
-
#datetime_greater_than(time_a, time_b) ⇒ Object
Returns a boolean if the first date/time is after the second.
-
#days_ago(time) ⇒ Object
Returns the number of days ago the passed date is.
-
#default_errors(errors) ⇒ Object
Generates HTML for FormErrorsDrop.
-
#dom_id(object, prefix = nil) ⇒ Object
Returns a string suitable for use as an HTML
id
attribute based on the passed drop. -
#duration(seconds) ⇒ Object
Returns text for the number of days, hours, minutes, and seconds for the passed number of seconds.
-
#embed_asset(asset, options = {}) ⇒ Object
Generates the HTML code to include an AssetDrop.
-
#fallback(original, *default_values) ⇒ Object
Returns the passed in value if it's not blank, otherwise the first non-blank alternate.
-
#field_input(field, *args) ⇒ Object
Renders a FormFieldDrop.
-
#filter_by_label(items, label) ⇒ Object
Filters an array of items to those that have a label on them.
-
#font_tags(settings) ⇒ Object
Generates the appropriate HTML to include the fonts required by the passed ThemeSettingsDrop.
-
#format_size(size) ⇒ Object
Returns a KB/MB/GB size of the passed number.
-
#h(s) ⇒ Object
Escapes a string for inclusion in HTML.
-
#image_tag(asset, options = {}) ⇒ Object
Generates an HTML <img> tag for the passed asset.
-
#image_url(asset, options = {}) ⇒ Object
Returns the URL for the passed asset.
-
#in_batches(items, no_of_batches) ⇒ Object
Groups the passed array into specified number of batches {{ array | in_batches 3 }}.
-
#in_batches_of(items, batch_size) ⇒ Object
Groups the passed array into batches of the specified size {{ array | in_batches_of: 2}}.
-
#lines(s) ⇒ Object
Converts a string with line breaks to an array.
-
#link_to(label, url, *args) ⇒ Object
Turns the passed text into an HTML link.
-
#link_with_loading_state(label, options = {}) ⇒ Object
Generates HTML for a link button with a loading state that shows when btn–loading classs is added to it Useful if the link triggers an async action (just add btn–loading class to the link when the action is triggered and remove it when it is completed) {{ 'Remove' | link_with_loading_state }}.
-
#media_tag(asset, options = {}) ⇒ Object
Generates HTML to display the passed AssetDrop.
-
#method_with_params(drop, method, options) ⇒ Object
Allow send settings/params to methods of drops that accepts params {{ affiliate_program | method_with_params: 'leaderboard_affiliates', section.settings }}.
-
#money(obj, microdata = false, options = {}) ⇒ Object
Formats the passed ProductDrop or PriceDrop's price, or number, as currency, optionally with microdata.
-
#money_format(dollars, options = {}) ⇒ Object
Creates a money object from passed number and currency and calls format with the rest of the passed options.
-
#ms_since_epoch(time) ⇒ Object
Returns the number of milliseconds since the Unix epoch (Jan 1, 1970).
-
#name_sentence(items) ⇒ Object
Maps an array of UserDrops to a sentence fragment of their names.
-
#number_with_delimiter(number, options = {}) ⇒ Object
Formats a number with grouped thousands using the provided delimiter(default is ',') {{ 10000 | number_with_delimiter: delimiter: ',' }}.
- #pluralize(count, singular) ⇒ Object deprecated Deprecated.
-
#pluralize_without_count(singular, count) ⇒ Object
Returns the pluralized form of a word for the passed number using the page's language.
-
#prepare_hash(hash_or_settings_drop, required_attrs, merge_with_hash = {}) ⇒ Object
Allow convert hash or ThemeSettingsDrop to hash with only required attributes and merge with other hash {{ hash_or_settings_drop | prepare_hash: 'count_products title', other_hash }}.
-
#price_data_attributes_for_price_switcher(price_drop, options = {}) ⇒ Object
Returns data attributes used by the product_price_switcher component.
-
#price_description(obj, options = {}) ⇒ Object
Returns HTML describing the passed PriceDrop or ProductDrop's price.
- #rails_asset_url(file) ⇒ Object deprecated Deprecated.
-
#random_string(length) ⇒ Object
Generates a random string of the given length {{ 5 | random_string }}.
-
#reading_time_minutes(s) ⇒ Object
Returns the estimated reading time of the passed string in minutes.
-
#reading_time_seconds(s) ⇒ Object
Returns the estimated reading time of the passed string in seconds.
-
#responsive_media_tag(asset, options = {}) ⇒ Object
Only images are supported.
-
#script_tag(file, extra = nil) ⇒ Object
Generates an HTML <script> tag to a script in the theme's
assets
directory. -
#setting_attrs(obj, setting_id) ⇒ Object
Returns HTML attributes for the passed SectionDrop for use in the editor.
-
#sha_256(string) ⇒ Object
Creates a SHA256 hex digest from a given string {{ 'test' | sha_256 }}.
-
#singularize(plural) ⇒ Object
Returns the singular form of a word using the page's language.
-
#slice(input, offset, length = nil) ⇒ Object
Returns a subsection of an array, CollectionDrop, or other object.
-
#stylesheet_link_tag(file) ⇒ Object
Generates an HTML <link> tag to a stylesheet in the theme's
assets
directory. - #svg_asset(asset_name, html_class) ⇒ Object
-
#t(key) ⇒ Object
deprecated
Deprecated.
Use #translate instead.
-
#ternary(value, true_output, untrue_output = '') ⇒ Object
Ternary Filter {{ true | ternary: 'this text will be rendered', 'this text will NOT be rendered' }}.
-
#time_unit_to_datetime_from_now(count, unit) ⇒ Object
Returns the date/time representing the moment the passed number and units in the future.
-
#to_json(obj) ⇒ Object
Convert an object to JSON.
-
#transfer_login(url) ⇒ Object
Generates A URL to another Simplero domain while maintaining the current login state.
-
#translate(key, *args) ⇒ Object
Returns the translated text in the user's language for the passed key.
-
#truncate_html(html, length = 500) ⇒ Object
Truncates the passed HTML to the passed
length
(default: 500). -
#u(s) ⇒ Object
Escapes a string for inclusion in a URL.
- #word_count(s) ⇒ Object deprecated Deprecated.
Methods included from GroupingFilters
Instance Method Details
#add_to_cart_link(product, options = {}) ⇒ Object
Generates HTML for an 'Add to cart' link for the given product. Optional attributes are class
{{ product | add_to_cart_link: class: 'btn btn-primary' }}
#address_html(object, sep = nil) ⇒ Object
Returns HTML for the passed object's address. Optionally pass in HTML for a separator (default is
.) {{ account | address_html, sep: '/' }}
#asset_url(file) ⇒ Object
Returns the URL for a file in the theme's assets
directory. {{ 'hero.jpg' | asset_url }}
#button_color_attrs(color) ⇒ Object
#bytes_to_gb(bytes) ⇒ Object
#dasherize(s) ⇒ Object
#date_only(d) ⇒ Object
Returns the formatted date portion of the passed date/time in the page's language. {{ member.created_at | date_only }}
#datetime(date_time, options = {}) ⇒ Object
Returns the formatted date and time of the passed date/time in the page's language. Optional attributes are no_date
(boolean), no_time
(boolean). If both are true, nil is returned. {{ member.created_at | datetime }}
#datetime_greater_than(time_a, time_b) ⇒ Object
Returns a boolean if the first date/time is after the second. {{ magna_carta_created | datetime_greater_than: genghis_khan_death }}
#days_ago(time) ⇒ Object
Returns the number of days ago the passed date is. {{ member.created_at | days_ago }}
#default_errors(errors) ⇒ Object
Generates HTML for FormErrorsDrop. {{ form.errors | default_errors }}
#dom_id(object, prefix = nil) ⇒ Object
Returns a string suitable for use as an HTML id
attribute based on the passed drop. Optionally pass a prefix. {{ course | dom_id, prefix: 'course_' }}
#duration(seconds) ⇒ Object
Returns text for the number of days, hours, minutes, and seconds for the passed number of seconds. {{ 3600 | duration }}
#embed_asset(asset, options = {}) ⇒ Object
Generates the HTML code to include an AssetDrop. Optionally pass in width
, height
, and alt
. {{ asset | embed_asset: width: 400 }}
#fallback(original, *default_values) ⇒ Object
Returns the passed in value if it's not blank, otherwise the first non-blank alternate. {{ customer.name | fallback: 'Bud' }}
#field_input(field, *args) ⇒ Object
Renders a FormFieldDrop. Optional attributes are input_class
, placeholder
(boolean), custom_placeholder
(string). {{ field | field_input: input_class: 'form-control', placeholder: true, custom_placeholder: 'Enter your email…' }}
#filter_by_label(items, label) ⇒ Object
Filters an array of items to those that have a label on them. {{ array | filter_by_label label }}
#font_tags(settings) ⇒ Object
Generates the appropriate HTML to include the fonts required by the passed ThemeSettingsDrop. {{ settings | font_tags }}
#format_size(size) ⇒ Object
Returns a KB/MB/GB size of the passed number. {{ 100000 | format_size }}
#h(s) ⇒ Object
Escapes a string for inclusion in HTML. {{ '5 > 1' | h }}
#image_tag(asset, options = {}) ⇒ Object
Generates an HTML <img> tag for the passed asset. Asset can be an AssetDrop or a reference to a file in the theme's assets
directory. Optionally pass:
-
alt
: alt attribute for the <img> tag -
dimensions
: dimensions for the <img> tagwidth
andheight
attributes, in a format such as100x50
. Iffalse
, nowidth
orheight
will be added. If not specified,width
andheight
will be the same as the image file's dimensions, if known. -
scale
: scale the image to fit these dimensions. Pass a format like100x50x
(for width and height),100
(for width only) orx50
for height only. Only has an effect on AssetDrops. -
class
: class attribute for the <img> tag
{{ 'hero.jpg' | image_tag: dimensions: '300x200' }}
#image_url(asset, options = {}) ⇒ Object
Returns the URL for the passed asset. Asset can be an AssetDrop or a reference to a file in the theme's assets
directory. Optionally pass in alt
, dimensions
, class
, and constrain
(fit, fill or crop). {{ 'hero.jpg' | image_url: dimensions: '300x200' }}
#in_batches(items, no_of_batches) ⇒ Object
Groups the passed array into specified number of batches {{ array | in_batches 3 }}
#in_batches_of(items, batch_size) ⇒ Object
Groups the passed array into batches of the specified size {{ array | in_batches_of: 2}}
#lines(s) ⇒ Object
Converts a string with line breaks to an array. {{ haiku | lines }}
#link_to(label, url, *args) ⇒ Object
Turns the passed text into an HTML link. Optionally include more HTML attributes. {{ 'my homepage' | link_to: 'example.com', target: '_blank' }}
#link_with_loading_state(label, options = {}) ⇒ Object
Generates HTML for a link button with a loading state that shows when btn–loading classs is added to it Useful if the link triggers an async action (just add btn–loading class to the link when the action is triggered and remove it when it is completed) {{ 'Remove' | link_with_loading_state }}
#media_tag(asset, options = {}) ⇒ Object
Generates HTML to display the passed AssetDrop. Optionally pass in: thumbnail
(boolean), height
, width
, max_height
, embedded_if_svg
(boolean), and alt
. # {{ asset | media_tag: thumbnail: true, width: 800 }}
#method_with_params(drop, method, options) ⇒ Object
Allow send settings/params to methods of drops that accepts params {{ affiliate_program | method_with_params: 'leaderboard_affiliates', section.settings }}
#money(obj, microdata = false, options = {}) ⇒ Object
Formats the passed ProductDrop or PriceDrop's price, or number, as currency, optionally with microdata. {{ product | money: true }}
#money_format(dollars, options = {}) ⇒ Object
Creates a money object from passed number and currency and calls format with the rest of the passed options. Refer to www.rubydoc.info/gems/money/Money/Formatter for available formatting options. {{ '1.23' | money_format: currency: 'USD', symbol: false, no_cents_if_whole: true }}
#ms_since_epoch(time) ⇒ Object
Returns the number of milliseconds since the Unix epoch (Jan 1, 1970). {{ member.created_at | ms_since_epoch }}
#name_sentence(items) ⇒ Object
Maps an array of UserDrops to a sentence fragment of their names. {{ course.authors | name_sentence }}
#number_with_delimiter(number, options = {}) ⇒ Object
Formats a number with grouped thousands using the provided delimiter(default is ',') {{ 10000 | number_with_delimiter: delimiter: ',' }}
#pluralize(count, singular) ⇒ Object
#pluralize_without_count(singular, count) ⇒ Object
Returns the pluralized form of a word for the passed number using the page's language. {{ 'cat' | pluralize_without_count: 2 }}
#prepare_hash(hash_or_settings_drop, required_attrs, merge_with_hash = {}) ⇒ Object
Allow convert hash or ThemeSettingsDrop to hash with only required attributes and merge with other hash {{ hash_or_settings_drop | prepare_hash: 'count_products title', other_hash }}
#price_data_attributes_for_price_switcher(price_drop, options = {}) ⇒ Object
Returns data attributes used by the product_price_switcher component. {{ price | price_data_attributes_for_price_switcher }}
#price_description(obj, options = {}) ⇒ Object
Returns HTML describing the passed PriceDrop or ProductDrop's price. {{ price | price_description }}
#rails_asset_url(file) ⇒ Object
#random_string(length) ⇒ Object
Generates a random string of the given length {{ 5 | random_string }}
#reading_time_minutes(s) ⇒ Object
Returns the estimated reading time of the passed string in minutes. {{ war_and_peace | reading_time_minutes }}
#reading_time_seconds(s) ⇒ Object
Returns the estimated reading time of the passed string in seconds. {{ war_and_peace | reading_time_seconds }}
#responsive_media_tag(asset, options = {}) ⇒ Object
Only images are supported. If some other type of AssetDrop is passed, it falls back to use media_tag
. Generates an HTML <img> tag for the passed asset with different srcset
for different device sizes. Specify different sizes of the image to be included in the srcset using sizes
- comma separated (the first value is used as the default src). And specify size hints for the browser for different devices using s
(<480px), m
(<768px), l
(<1024px), xl
(<1280px), xl2
(<1366px), xl3
(<1600px), 'xl4
(>1600px).
#script_tag(file, extra = nil) ⇒ Object
Generates an HTML <script> tag to a script in the theme's assets
directory. {{ 'theme.coffee' | script_tag }}
#setting_attrs(obj, setting_id) ⇒ Object
Returns HTML attributes for the passed SectionDrop for use in the editor. {{ section | setting_attrs: 'title' }}
#sha_256(string) ⇒ Object
Creates a SHA256 hex digest from a given string {{ 'test' | sha_256 }}
#singularize(plural) ⇒ Object
Returns the singular form of a word using the page's language. {{ 'cats' | singularize }}
#slice(input, offset, length = nil) ⇒ Object
Returns a subsection of an array, CollectionDrop, or other object. First parameter is where to start. Second parameter is how many elements from the starting point to return (default: all). {{ array | slice: 2, 1 }}
#stylesheet_link_tag(file) ⇒ Object
Generates an HTML <link> tag to a stylesheet in the theme's assets
directory. {{ 'theme' | stylesheet_link_tag }}
#svg_asset(asset_name, html_class) ⇒ Object
#t(key) ⇒ Object
Use #translate instead.
#ternary(value, true_output, untrue_output = '') ⇒ Object
Ternary Filter {{ true | ternary: 'this text will be rendered', 'this text will NOT be rendered' }}
#time_unit_to_datetime_from_now(count, unit) ⇒ Object
Returns the date/time representing the moment the passed number and units in the future. {{ 1 | time_unit_to_datetime_from_now: 'days' }}
#to_json(obj) ⇒ Object
Convert an object to JSON. {{ course | to_json }}
#transfer_login(url) ⇒ Object
Generates A URL to another Simplero domain while maintaining the current login state. {{ 'example.simplero.com' | transfer_login }}
#translate(key, *args) ⇒ Object
Returns the translated text in the user's language for the passed key. These translations are provided by Simplero. {{ 'blog.all.no_posts' | translate }}
#truncate_html(html, length = 500) ⇒ Object
Truncates the passed HTML to the passed length
(default: 500). Avoids truncating in the middle of an HTML tag or leaving unclosed tags. {{ macbeth | truncate_html, length: 250 }}
#u(s) ⇒ Object
Escapes a string for inclusion in a URL. {{ 'some text' | u }}