nisetegami 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## Nisetegami
2
2
 
3
-
3
+ Authors: Denis Lifanov, Dmitry Afanasyev
4
4
 
5
5
  This project rocks and uses MIT-LICENSE.
@@ -17,3 +17,7 @@ table {
17
17
  form.filters table {
18
18
  text-align: left;
19
19
  }
20
+
21
+ .red {
22
+ color: red;
23
+ }
@@ -11,7 +11,6 @@ module Nisetegami
11
11
  %w(name subject from reply_to cc bcc).each do |attr|
12
12
  @templates = @templates.where(["#{attr} LIKE ?", "%#{params[attr]}%"]) unless params[attr].blank?
13
13
  end
14
- @templates = @templates.all
15
14
  end
16
15
 
17
16
  def actions
@@ -24,11 +24,11 @@ class Nisetegami::Template < ActiveRecord::Base
24
24
 
25
25
  address_re = "(?:[^<@]+\\s+<#{Nisetegami.email_re}>|#{Nisetegami.email_re})"
26
26
  addresses_re = /^#{address_re}(?:\s*,\s*#{address_re})*$/i
27
- validates_format_of :from, :reply_to, :cc, :bcc, with: addresses_re, allow_blank: true
28
- validate :name, :subject, :body_text, :layout_text, presence: true
29
- validate :body_html, :layout_html, presence: true, unless: :only_text?
30
- validate :check_template_syntax
31
- validate :check_mailer
27
+ validates :from, :reply_to, :cc, :bcc, format: {with: addresses_re}, allow_blank: true
28
+ validates :name, :subject, :body_text, presence: true
29
+ validates :body_html, presence: true, unless: :only_text?
30
+ validate :check_template_syntax
31
+ validate :check_mailer
32
32
 
33
33
  ## callbacks
34
34
 
@@ -1,6 +1,9 @@
1
1
  <div class="control-group">
2
2
  <%= f.label attr, class: 'control-label' %>
3
3
  <div class="controls">
4
+ <% if f.object.errors[attr] %>
5
+ <span class="red"><%= f.object.errors[attr].join(', ') %></span>
6
+ <% end %>
4
7
  <%= (input = yield).present? ? input : f.text_field(attr) %>
5
8
  </div>
6
9
  </div>
@@ -0,0 +1,14 @@
1
+ Nisetegami.configure do |config|
2
+ # Cast variables types
3
+ # config.cast do |klass|
4
+ # begin
5
+ # "#{klass}Decorator".constantize
6
+ # rescue
7
+ # klass.constantize
8
+ # end
9
+ # end
10
+
11
+ # Mailers mapping
12
+ # config.register 'UserMailer', :signup, user, temporary_password, created_at: 'DateTime'
13
+ # config.register 'UserMailer', :notice, user, notice, additional_attributes: 'Hash'
14
+ end
@@ -5,7 +5,7 @@ class CreateNisetegamiTemplates < ActiveRecord::Migration
5
5
  ## mapping
6
6
  t.string :mailer # EG: "TestMailer"
7
7
  t.string :action # EG: "simple"
8
- t.string :name # results in "TestMailer#simple"
8
+ t.string :name
9
9
 
10
10
  ## headers
11
11
  t.string :from
@@ -1,10 +1,10 @@
1
1
  require 'rails/generators'
2
2
  require 'rails/generators/migration'
3
3
 
4
- class Nisetegami::TemplatesGenerator < Rails::Generators::Base
4
+ class NisetegamiGenerator < Rails::Generators::Base
5
5
  include Rails::Generators::Migration
6
6
 
7
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
7
+ source_root File.dirname(__FILE__)
8
8
 
9
9
  def self.next_migration_number(dirname)
10
10
  if ActiveRecord::Base.timestamped_migrations
@@ -14,6 +14,10 @@ class Nisetegami::TemplatesGenerator < Rails::Generators::Base
14
14
  end
15
15
  end
16
16
 
17
+ def create_config_file
18
+ template 'initializers/nisetegami.rb', 'config/initializers/nisetegami.rb'
19
+ end
20
+
17
21
  def create_migrations
18
22
  Dir[File.join(self.class.source_root, 'migrations/*.rb')].sort.each do |template|
19
23
  basename = File.basename(template).gsub(/^\d+_/, '')
@@ -19,7 +19,7 @@ module Nisetegami
19
19
  mattr_reader :mapping
20
20
  @@mapping = Nisetegami::Mapping.new
21
21
 
22
- mattr_accessor :email_re
22
+ mattr_reader :email_re
23
23
  @@email_re = /[-a-z0-9_+\.]+@([-a-z0-9]+\.)+[a-z0-9]{2,}/
24
24
 
25
25
  def self.configure
@@ -29,7 +29,15 @@ module Nisetegami
29
29
  # optional block to cast a thing (String, Symbol)
30
30
  # into a class with liquid_methods
31
31
  def self.cast(&block)
32
- @@cast ||= ->(thing){ defined?(thing) == 'constant' ? thing : thing.to_s.constantize }
32
+ @@cast ||= ->(thing) do
33
+ if defined?(thing) == 'constant'
34
+ thing
35
+ elsif const_defined?(thing.to_s)
36
+ thing.to_s.constantize
37
+ else
38
+ String
39
+ end
40
+ end
33
41
  block_given? ? @@cast = block : @@cast
34
42
  end
35
43
 
@@ -1,3 +1,3 @@
1
1
  module Nisetegami
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  namespace :nisetegami do
2
2
  namespace :templates do
3
3
  desc "Populate nisetegami templates with sample data"
4
- task :populate => :environment do
4
+ task populate: :environment do
5
5
  Nisetegami.populate!
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nisetegami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-09 00:00:00.000000000 Z
13
+ date: 2012-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -169,8 +169,9 @@ files:
169
169
  - config/locales/nisetegami.en.yml
170
170
  - config/locales/nisetegami.ru.yml
171
171
  - config/routes.rb
172
- - lib/generators/nisetegami/templates/migrations/001_create_nisetegami_templates.rb
173
- - lib/generators/nisetegami/templates_generator.rb
172
+ - lib/generators/initializers/nisetegami.rb
173
+ - lib/generators/migrations/001_create_nisetegami_templates.rb
174
+ - lib/generators/nisetegami_generator.rb
174
175
  - lib/nisetegami/action_mailer_extensions.rb
175
176
  - lib/nisetegami/ar_template_resolver.rb
176
177
  - lib/nisetegami/asset_provider.rb