Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

locomotivecms-solid

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locomotivecms-solid

  • 4.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
3
Created
Source

Solid

Solid aim to provide a easier and nicer API to create custom Liquid tags and blocks

Installation

Due to a name conflict the gem is called tigerlily-solid. So to use it:

gem 'tigerlily-solid', :require => 'solid'

Build Status Build Status

Tags

To create a new tag, you just have to:

  • Extend Solid::Tag
  • Define a display method
  • Give a tag_name
class DummyTag < Solid::Tag

  tag_name :dummy # register in Liquid under the name of `dummy`

  def display
    'dummy !!!'
  end

end
<p>{% dummy %}<p>

Arguments

This is the simpliest tag ever but, Solid tags can receive rich arguments:

class TypeOfTag < Solid::Tag

  tag_name :typeof

  def display(*values)
    ''.tap do |output|
      values.each do |value|
        output << "<p>Type of #{value} is #{value.class.name}</p>"
      end
    end
  end

end
{% capture myvar %}eggspam{% endcapture %}
{% typeof "foo", 42, 4.2, myvar, myoption:"bar", otheroption:myvar %}
<!-- produce -->
<p>Type of "foo" is String</p>
<p>Type of 42 is Integer</p>
<p>Type of 4.2 is Float</p>
<p>Type of "eggspam" is String</p>
<p>Type of {:myoption=>"bar", :otheroption=>"eggspam"} is Hash</p>

Context attributes

If there is some "global variables" in your liquid context you can declare that your tag need to access it:

class HelloTag < Solid::Tag

  tag_name :hello

  context_attribute :current_user

  def display
    "Hello #{current_user.name} !"
  end

end
<p>{% hello %}</p>
<!-- produce -->
<p>Hello Homer</p>

Blocks

Block are just tags with a body. They perform the same argument parsing. To render the block body from it's display method you just have to yield:

class PBlock < Solid::Block

  tag_name :p

  def display(options)
    "<p class='#{options[:class]}'>#{yield}</p>"
  end

end
{% p class:"content" %}
  It works !
{% endp %}
<!-- produce -->
<p class="content">It works !</p>

Of course you are free to yield once, multiple times or even never.

Conditional Blocks

Conditional blocks are blocks with two bodies. If you yield true you will receive the main block and if you yield false you will receive the else block:

class IfAuthorizedToTag < Solid::ConditionalBlock

  tag_name :if_authorized_to

  context_attribute :current_user

  def display(permission)
    yield(current_user.authorized_to?(permission))
  end

end
{% if_authorized_to "publish" %}
  You are authorized !
{% else %}
  Get out !
{% endif_authorized_to %}

License

Solid is released under the MIT license:

http://www.opensource.org/licenses/MIT

FAQs

Package last updated on 13 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc