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

Methods included from GroupingFilters

#group_by

Instance Method Details

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

Deprecated.

#bytes_to_gb(bytes) ⇒ Object

#dasherize(s) ⇒ Object

Deprecated.

#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> tag width and height attributes, in a format such as 100x50. If false, no width or height will be added. If not specified, width and height will be the same as the image file's dimensions, if known.

  • scale: scale the image to fit these dimensions. Pass a format like 100x50x (for width and height), 100 (for width only) or x50 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 }}

Turns the passed text into an HTML link. Optionally include more HTML attributes. {{ 'my homepage' | link_to: 'example.com', target: '_blank' }}

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

Deprecated.

#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

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. {{ 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 }}

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

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. {{ 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 }}

#word_count(s) ⇒ Object

Deprecated.