Liquid ExtentionS for MOre Komfort
Read about Liquid at:
Make any class "meltable" quickly:
class FilmFanatic::Movie
include ::Lesmok::Acid::Meltable
end
... and you can start using it in your Liquid templates immediately.
NOTE: All methods are now delegated (ACID - All Content Is Delegated), so you don't want to do this if your liquid templates are "untrustworthy" or your object has potentially destructive methods.
The Lesmok::Acid::Drop
liquid-drop class is used by default unless you:
- specify a
to_liquid
method explicitly in your class, - override
liquify_drop_klass
to return your preferred sub-class ofLiquid::Drop
, - or create an adjacent
*Drop
class with same naming as your model class.
class FilmFanatic::MovieDrop < ::Lesmok::Acid::Drop # Quick-n-dirty start.
alias :movie :source_object # For readability.
def rave # Start adding presenter methods you need.
"OMG! #{movie.title} is so awesome!"
end
end
As you clean up, you may want to have more explicit drop control and migrate away from using Acid Drop:
class FilmFanatic::MovieDrop < ::Liquid::Drop
include ::Lesmok::Acid::Droppable # To keep compatible with Acid::Drop
alias :movie :source_object
end
Given that your object has a cache key, you can use the cached_include
tag in your liquid templates:
class FilmFanatic::Movie
include ::Lesmok::Acid::Meltable
def cache_key
"fantastic-movie-#{self.imdb_id}"
end
end
Then from your template:
{% cached_include 'my/movie/reviews/liquid/template' for { cache_on: fantastic_movie } %}
Add this line to your application's Gemfile:
gem 'lesmok'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lesmok
Lesmok.configure do |conf|
conf.logger = Rails.logger
conf.available_cache_stores = {
default: Rails.cache,
redis: $redis # Using Redis is entirely optional.
}
conf.debugging_enabled = Rails.env.development?
conf.caching_enabled = proc { Rails.env.production? }
conf.raise_errors_enabled = Rails.env.development?
end
Lesmok::Liquid::Tags.register_tags
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request