merimee 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Damien Couture
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -10,34 +10,26 @@ _merimee_ adds some rspec macros (Test::Case to come ... maybe) to add automatic
10
10
  gem 'merimee'
11
11
  ```
12
12
 
13
- ## Configuration
13
+ ## Usage
14
14
 
15
- The config object has the following methods/arguments :
15
+ ### Rspec/rails
16
+ Just drop a `require 'merimee'` in your `spec_helper.rb`.
17
+ It gives you the following in your views :
16
18
 
17
19
  ```ruby
18
- Merime::Checker.new do |config|
19
- # Ignore OHAI spelling errors. This is case sensitive for now, feel free to tell me if you feel it shouldn't be the case.
20
- config.dict_add 'OHAI'
21
- config.dict_add %w{Trealiu Chtulu} # Ignore other words, method takes any enumerable too !
22
-
23
- # Ignore all words contained in blah.txt, one per line
24
- config.dict_add_file 'blah.txt'
25
-
26
- # English by default, but AfterTheDeadline also supports French(fr), Spanish(es), German(de), Portuguese(pt)
27
- config.language = 'en'
20
+ describe 'splash/index' do
21
+ it_should_have_correct_spelling
22
+ end
28
23
 
29
- # AtD says that you should provide a key, unique per use. You don't need to register/get it, but
30
- # you can't have more than one request on their servers at the same time with the same key.
31
- # Since merimee is intended for test mode, it should be fine.
32
- config.api_key = 'blah'
33
-
34
- # You can ignore some types of errors.
35
- config.ignore_types << 'spelling'
24
+ # Which is equivalent to
25
+ describe 'splash/logout' do
26
+ it "should have a correct spelling" do
27
+ render
28
+ rendered.should have_a_correct_spelling
29
+ end
36
30
  end
37
31
  ```
38
32
 
39
- ## Usage
40
-
41
33
  ### Standalone use
42
34
 
43
35
  Well, you need to initalize a `Merimee::Checker` with a `Merimee::Config`
@@ -55,21 +47,32 @@ checker.check('This text has one BIGE error')
55
47
 
56
48
  Error objects have some interesting fields (`type`, `suggestions`, `url`, `description`), inspect them to know more.
57
49
 
58
- ### Rspec/rails
59
- Just drop a `require 'merimee'` in your `spec_helper.rb`.
60
- It gives you the following in your views :
50
+ ## Configuration
51
+
52
+ The config object has the following methods/arguments :
61
53
 
62
54
  ```ruby
63
- describe 'splash/index' do
64
- it_should_have_correct_spelling
65
- end
55
+ Merime::Checker.new do |config|
56
+ # Ignore OHAI spelling errors. This is case sensitive for now, feel free to tell me if you feel it shouldn't be the case.
57
+ config.dict_add 'OHAI'
58
+ config.dict_add %w{Trealiu Chtulu} # Ignore other words, method takes any enumerable too !
66
59
 
67
- # Which is equivalent to
68
- describe 'splash/logout' do
69
- it "should have a correct spelling" do
70
- render
71
- rendered.should have_a_correct_spelling
72
- end
60
+ # Ignore all words contained in blah.txt, one per line
61
+ config.dict_add_file 'blah.txt'
62
+
63
+ # English by default, but AfterTheDeadline also supports French(fr), Spanish(es), German(de), Portuguese(pt)
64
+ config.language = 'en'
65
+
66
+ # AtD says that you should provide a key, unique per use. You don't need to register/get it, but
67
+ # you can't have more than one request on their servers at the same time with the same key.
68
+ # Since merimee is intended for test mode, it should be fine.
69
+ config.api_key = 'blah'
70
+
71
+ # You can ignore some types of errors.
72
+ # Some are already ignored by default, see Merimee::DEFAULT_IGNORE_TYPES in lib/merimee/config.rb
73
+ config.ignore 'spelling', 'grammar'
74
+ # You can also include some types that were ignored
75
+ config.error 'cliches', 'double negatives'
73
76
  end
74
77
  ```
75
78
 
@@ -85,9 +88,24 @@ RSpec.configure do |config|
85
88
  end
86
89
  ```
87
90
 
91
+ Or you can set your config in your test (for example to ignore just a word in one view) :
92
+
93
+ ```ruby
94
+ describe "blah/index" do
95
+ it_should_have_correct_spelling do |config|
96
+ config.dict_add "mybrand"
97
+ end
98
+ end
99
+ ```
100
+
88
101
  ## Known issues
89
102
 
90
103
  See http://github.com/coutud/merimee/issues
104
+ Feel free to fork, send request (especially for Test::Case ... I'm a bit lazy for that).
105
+
106
+ ## License
107
+
108
+ This gem is licensed under the MIT license. See LICENSE.md
91
109
 
92
110
  ## Thanks etc.
93
111
 
data/Rakefile CHANGED
@@ -12,3 +12,5 @@ desc "Open an irb session preloaded with this library"
12
12
  task :console do
13
13
  sh "irb -rubygems -I lib -r merimee.rb"
14
14
  end
15
+
16
+ task :default => :test
data/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+
2
+ * Allow for case sensitive/insensitive add in dictionary
3
+ * Allow some error types to throw errors, and some to just output warnings
@@ -2,6 +2,7 @@ require "merimee/version"
2
2
 
3
3
  require "merimee/checker"
4
4
  require "merimee/config"
5
+ require "merimee/error"
5
6
  require "merimee/after_the_deadline"
6
7
 
7
8
  require 'merimee/railties/merimee_railtie.rb' if defined?(Rails)
@@ -53,7 +53,7 @@ class AfterTheDeadline
53
53
  private_class_method :perform
54
54
  end
55
55
 
56
- class AfterTheDeadline::Error
56
+ class AfterTheDeadline::Error < Merimee::Error
57
57
  attr_reader :string, :description, :precontext, :type, :suggestions, :url
58
58
 
59
59
  def initialize(hash)
@@ -13,15 +13,18 @@ module Merimee
13
13
  AfterTheDeadline.key = @config.api_key
14
14
  errors = AfterTheDeadline.check(text)
15
15
 
16
- # Remove any error types we don't care about
17
- errors.reject! { |e| @config.ignore_types.include?(e.description) }
18
-
19
16
  # Remove spelling errors from our custom dictionary
20
17
  # Also remove stuff that is obviously not a word (AtD seems to have issues sometime)
21
18
  errors.reject! do |e|
22
19
  e.type == 'spelling' &&
23
20
  @config.dictionary.include?(e.string)
24
21
  end
22
+
23
+ # Remove any error types we don't care about
24
+ errors.each do |err|
25
+ err.severity = @config.severity[err.description.downcase] || :error
26
+ end
27
+
25
28
  errors
26
29
  end
27
30
 
@@ -1,12 +1,12 @@
1
1
  require 'digest/sha1'
2
2
 
3
3
  module Merimee
4
- DEFAULT_IGNORE_TYPES = ['Bias Language', 'Cliches', 'Complex Expression', 'Diacritical Marks', 'Double Negatives', 'Hidden Verbs', 'Jargon Language', 'Passive voice', 'Phrases to Avoid', 'Redundant Expression']
4
+ DEFAULT_IGNORE_TYPES = ['bias language', 'cliches', 'complex expression', 'diacritical marks', 'double negatives', 'hidden verbs', 'jargon language', 'passive voice', 'phrases to avoid', 'redundant expression']
5
5
  DEFAULT_LANGUAGE = 'en'
6
6
 
7
7
  class Config
8
- attr_reader :dictionary
9
- attr_accessor :ignore_types
8
+ attr_accessor :dictionary
9
+ attr_reader :severity
10
10
 
11
11
  # This is required by the service for caching purposes,
12
12
  # but no registration is needed (api_key should just be unique for
@@ -20,11 +20,31 @@ module Merimee
20
20
 
21
21
  def initialize
22
22
  @dictionary = []
23
- @ignore_types = Merimee::DEFAULT_IGNORE_TYPES
23
+ @severity = {}
24
+ ignore(Merimee::DEFAULT_IGNORE_TYPES)
25
+
24
26
  @api_key = Config.generate_api_key
25
27
  @language = Merimee::DEFAULT_LANGUAGE
26
28
  end
27
29
 
30
+ def ignore(types)
31
+ set_type_severity(types, :ignore)
32
+ end
33
+ def warn(types)
34
+ set_type_severity(types, :warn)
35
+ end
36
+ def error(types)
37
+ set_type_severity(types, :error)
38
+ end
39
+ def set_type_severity(types, level)
40
+ unless types.kind_of?(Enumerable)
41
+ types = [types]
42
+ end
43
+ types.each do |t|
44
+ @severity[t.to_s.downcase] = level
45
+ end
46
+ end
47
+
28
48
  def dict_add(word)
29
49
  if word.kind_of?(String)
30
50
  @dictionary << word
@@ -37,6 +57,15 @@ module Merimee
37
57
  File.open(file) {|f| dict_add(f.readlines.map(&:strip)) }
38
58
  end
39
59
 
60
+ def clone
61
+ ret = Config.new
62
+ ret.dictionary = @dictionary.dup
63
+ ret.severity.update(@severity)
64
+ ret.api_key = api_key
65
+ ret.language = language
66
+ ret
67
+ end
68
+
40
69
  private
41
70
  # We just use the path to this file, and the current hostname
42
71
  # If you
@@ -0,0 +1,5 @@
1
+ module Merimee
2
+ class Error
3
+ attr_accessor :severity
4
+ end
5
+ end
@@ -1,22 +1,28 @@
1
1
  module Merimee
2
2
  module Rspec
3
3
  module ViewCheckerHelper
4
- RSpec::Matchers.define :have_a_correct_spelling do
5
- match do |rendered|
6
- checker = Merimee::Checker.new(::RSpec.configuration.merimee_config)
4
+ class HaveACorrectSpellingMatcher
5
+ def initialize
6
+ @config = ::RSpec.configuration.merimee_config
7
+ yield @config if block_given?
8
+ end
9
+
10
+ def matches?(rendered)
11
+ checker = Merimee::Checker.new(@config)
7
12
 
8
13
  if rendered
9
14
  @errors = checker.check(rendered)
10
- @errors.empty?
15
+ @errors.none? {|e| e.severity == :error}
11
16
  else
12
17
  true
13
18
  end
14
19
  end
15
- failure_message_for_should do |view|
20
+
21
+ def failure_message_for_should
16
22
  errs = []
17
- @errors.each do |err|
18
- message = "[#{err.type}] #{err.string}"
19
- if err.suggestions
23
+ @errors.sort_by(&:severity).each do |err|
24
+ message = "[#{err.severity} : #{err.type} - #{err.description}] #{err.string}"
25
+ unless err.suggestions.empty?
20
26
  message << " (suggested: #{err.suggestions.join(', ')})"
21
27
  end
22
28
  errs << message
@@ -25,10 +31,10 @@ module Merimee
25
31
  end
26
32
  end
27
33
 
28
- def it_should_have_a_correct_spelling
34
+ def it_should_have_a_correct_spelling(&block)
29
35
  it "should have a correct spelling" do
30
36
  render
31
- rendered.should have_a_correct_spelling
37
+ rendered.should HaveACorrectSpellingMatcher.new(&block)
32
38
  end
33
39
  end
34
40
  end
@@ -1,3 +1,3 @@
1
1
  module Merimee
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,8 +6,8 @@ class ConfigTest < MiniTest::Unit::TestCase
6
6
  @config = Merimee::Config.new
7
7
  end
8
8
 
9
- def test_ignore_type_not_empty_by_default
10
- refute_empty @config.ignore_types
9
+ def test_some_types_ignored_by_default
10
+ assert @config.severity.any? {|k,v| v == :ignore }
11
11
  end
12
12
 
13
13
  def test_add_dict_with_word
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merimee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-24 00:00:00.000000000 Z
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &70305273190660 !ruby/object:Gem::Requirement
16
+ requirement: &70137566869380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70305273190660
24
+ version_requirements: *70137566869380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70305273190080 !ruby/object:Gem::Requirement
27
+ requirement: &70137566868820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70305273190080
35
+ version_requirements: *70137566868820
36
36
  description: Automatically submit your rendered views to AfterTheDeadline free spell
37
37
  check service, and make sure you don't have any errors in your views !
38
38
  email:
@@ -43,12 +43,15 @@ extra_rdoc_files: []
43
43
  files:
44
44
  - .gitignore
45
45
  - Gemfile
46
+ - LICENSE.md
46
47
  - README.md
47
48
  - Rakefile
49
+ - TODO.md
48
50
  - lib/merimee.rb
49
51
  - lib/merimee/after_the_deadline.rb
50
52
  - lib/merimee/checker.rb
51
53
  - lib/merimee/config.rb
54
+ - lib/merimee/error.rb
52
55
  - lib/merimee/railties/merimee_railtie.rb
53
56
  - lib/merimee/rspec/view_checker_helper.rb
54
57
  - lib/merimee/version.rb