Skip to content

Instantly share code, notes, and snippets.

@viniciusnz
Last active July 26, 2017 13:43
Show Gist options
  • Save viniciusnz/1520882183cf4308c73b53a77bdef621 to your computer and use it in GitHub Desktop.
Save viniciusnz/1520882183cf4308c73b53a77bdef621 to your computer and use it in GitHub Desktop.
x = NotificationEventCategory.where(title: 'purchase_concluded').first_or_initialize
x.save
n = Newsletter.new
n.title = 'xxx'
n.subject = '{{person.name}}'
n.body = '{{person.name}} e muito legal'
n.save
ne = n.notification_events.new
ne.notification_event_category_id = x.id
ne.save
@person_cart = Person.find(1).current_cart
NotificationEventCategory.send_notification(:purchase_concluded, {person_cart_id: @person_cart.id, person_id: @person_cart.person_id})
s = Sms.new
s.title = 'xxx'
s.body = '{{company.title}} e muito legal'
s.save
se = s.notification_events.new
se.notification_event_category_id = x.id
se.save
# make sure person_id 1 has a phone
NotificationEventCategory.send_notification(:purchase_concluded, {person_id: 1, company_id: 1})
# to add a field to liquid
Person.add_field(:current_cart, {resourceable_type: :showable, after: :current_company_member})
# see blog_post_render_about
class Liquid::RecToolDrop < Liquid::Drop
def initialize(options = {})
@mailer = options[:context]
end
def rec_suggestions
@mailer.render_to_string(partial: 'person_mailer/rec_suggestions').html_safe
end
def render_template(current_template)
@mailer.render_to_string(partial: "person_mailer/#{current_template}").html_safe
end
def hide_unlimited
RecTool.hide_unlimited(@person)
end
METHODS = [
:cached_recs_count, :global_cached_recs_count, :cached_cities_count, :global_cached_cities_count, :cached_countries_count, :cached_classes_count, :global_cached_classes_count
]
def liquid_method_missing(method)
if method.starts_with? "render_"
render_template(method.gsub(/\Arender_/, ''))
elsif METHODS.include?(method.try(:to_sym))
RecTool.send(method)
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment