Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A simple Rails view presenter for those with discerning taste. From the Library of Knowledge and Power
Add this line to your application's Gemfile:
gem 'lokap-presenter'
See https://rubydoc.info/github/adambair/lokap-presenter
Call the presenter within your view using the present
helper:
present(object, :class_name).render('template')
Your Presenter will be searched for in:
app/presenters/<class_name>_presenter.rb
Templates will be searched for in:
app/views/presenters/<class_name>/_default.html.erb
app/views/presenters/<class_name>/_<template>.html.erb
And can be used like so:
present(@person, :emotion).render
# => app/presenters/emotion_presenter.rb
# => app/views/presenters/emotion/_default.html.erb
present(@person, :emotion).render(:happy)
# => app/presenters/emotion_presenter.rb
# => app/views/presenters/emotion/_happy.html.erb
present(@person, :emotion).render(:sad)
# => app/presenters/emotion_presenter.rb
# => app/views/presenters/emotion/_sad.html.erb
Access the presenter inside your presenter templates:
presenter.show_emotion
p.show_emotion
The class has full access to the view... and view helpers, etc. Think of this as a helper on steroids (but less angry)
class EmotionPresenter < Lokap::Presenter
presents :person
delegate :emotions, :moods, to: :human
def who_is_this
person
end
def show_emotion
emotions.logic
end
def show_mood
moods.logic
end
end
If a specified template is not found, the presenter will attempt to render a default view.
present(@person, :share).render(:twitter)
# looks for /views/presenters/share/_twitter.html.erb (doesn't exist)
# => /views/presenters/share/_default.html.erb
This will also work for templates inside subfolders:
present(@person, :share).render('social/twitter')
# looks for /views/presenters/share/social/_twitter.html.erb (doesn't exist)
# => /views/presenters/share/social/_default.html.erb
Here are a few different ways to utilize presenters:
# Render (Default)
present(@person, :share).render
present(@person, :share).render(:twitter)
present(@person, :share).render('social/twitter')
# Block
present(@person, :share) do |p|
link_to p.text, p.url
end
# Object
share = present(@person, :share)
share.render(:twitter)
share.render(:facebook)
share.render(:email)
FAQs
Unknown package
We found that lokap-presenter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.