Skip to content

HitFox/mailfox

Repository files navigation

alt text

Mailfox

Build Status Gem Code Climate Coverage

The Mailfox gem lets you quickly add Mailchimp-integrated newsletter signup forms to your application. You can render these forms straight in your application or through the HitFox fork of Comfortable Mexican Sofa.

Installation

Add this to your Gemfile:

gem 'mailfox'

Add a mailfox_settings.yml file to your +config+ folder with the default configurations:

  mailchimp:
    api_key:
    list_id:
      customer:

Add a mailfox.rb file to your config/initializers folder:

  Mailfox.setup do |config|
    config.mailservices = YAML.load_file("#{Rails.root}/config/mailfox_settings.yml")
  end

Add the following line to your routes.rb file:

  mount Mailfox::Engine => "/mp"

Usage

You can now paste this into a view if you want to render a newsletter subscribe form:

  <%= render partial: "mailfox/newsletters/form", locals: {placeholder: '[email protected]', list_id: 'exampleID', disable_with_message: 'exampleMessage', submit_button_message: 'exampleSubmit'} %>

Or, if you are using the HitFox fork of CMS, you can create a snippet for easy use on your pages:

  {{ cms:field:newsletter.list_id }}
  {{ cms:field:newsletter.placeholder }}
  {{ cms:field:newsletter.disable_with_message }}
  {{ cms:field:newsletter.button }}

  {{ cms:partial:mailfox/newsletters/cms/form }}

Customizing Your Implementation

You can customize most of the end-user behavior of the Mailfox to suit your own needs. If the default view structure does not work for you, add a new _form.html.haml file in app/views/mailfox/newsletters.

Success and errors can be customized in the create.js.erb file in the same directory.

One note: if you want to access your host application's helper methods, add a helper file like this in app/helpers/mailfox/newsletters_helper.rb:

  Module Mailfox
    Module NewslettersHelper
      include ::MyHelper
    end
  end

Changelog

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/mailfox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.