liquid-validator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b96399f68410e3091b572d0c2a81f0f7d441365
4
+ data.tar.gz: 50d66ec57f08f4e91e141f5f509a60c55d08e5d9
5
+ SHA512:
6
+ metadata.gz: cb3684b2925d0acdb54d60af77efafbf49988c5a780b5665772c71966171166544ef09c9ac5aa27c7c142cb32a197a73091fe86fa51d18f132b05e5784a1de96
7
+ data.tar.gz: 964adea4e824ad266fda983715488ca83f62bef63afb08f159e406ead9e1e2d908f9686591d417340d349ec2570769909166cfa2ea7f5d22b42ada5100dc4e62
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeremy W. Rowe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # LiquidValidator
2
+
3
+ Is a simple way to validate your Liquid Template strings before creating a
4
+ Liquid Template object without raising error. If you do want to raise
5
+ an error and handle yourself consider then this gem isn't for you.
6
+
7
+ This is a very simple gem, that is the point.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'liquid-validator'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install liquid-validator
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ good_tmpl = "Your name is {{name}}"
27
+ validator = LiquidValidator::Validate.new(good_tmpl)
28
+ validator.valid? # true
29
+ validator.errors # []
30
+
31
+ bad_tmpl = "Your name is {{name"
32
+ validator = LiquidValidator::Validate.new(bad_tmpl)
33
+ validator.valid? # false
34
+ validator.errors # ["Syntax Error: ..."] (Array of strings)
35
+ ```
36
+
37
+ *Note* - That in ```LiquidValidator::Validate.new(tmpl)``` tmpl is a string.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "bundler/setup"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.pattern = "test/*_test.rb"
7
+ end
@@ -0,0 +1,4 @@
1
+ require "liquid"
2
+ require "liquid-validator/version"
3
+ require "liquid-validator/validator"
4
+ module LiquidValidator; end
@@ -0,0 +1,21 @@
1
+ class LiquidValidator::Validator
2
+ def initialize(template)
3
+ @template = template
4
+ @errors = []
5
+ @is_valid = false
6
+ run_validations_on_template
7
+ end
8
+
9
+ def valid?; @is_valid; end
10
+ def errors; @errors; end
11
+
12
+ private
13
+ def run_validations_on_template
14
+ begin
15
+ ::Liquid::Template.parse(@template)
16
+ @is_valid = true
17
+ rescue Exception => e
18
+ @errors << e.message
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module LiquidValidator
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'liquid-validator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "liquid-validator"
8
+ spec.version = LiquidValidator::VERSION
9
+ spec.authors = ["Jeremy W. Rowe"]
10
+ spec.email = ["jeremy.w.rowe@gmail.com"]
11
+ spec.description = %q{Liquid template validator}
12
+ spec.summary = %q{Validates template strings that are consumed when creating a liquid template. It is simple, that is the point.}
13
+ spec.homepage = "https://github.com/jeremywrowe/liquid-validator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency('liquid', '>= 2.4.0')
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,46 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require_relative '../lib/liquid-validator'
4
+
5
+ describe LiquidValidator::Validator do
6
+ describe "#valid?" do
7
+ it "returns true for valid templates" do
8
+ template = <<-TEMPLATE
9
+ {% if something %}
10
+ HAPPY DAY
11
+ {% endif %}
12
+ TEMPLATE
13
+ LiquidValidator::Validator.new(template).valid?.must_equal true
14
+ end
15
+
16
+ it "returns false for invalid templates" do
17
+ template = <<-TEMPLATE
18
+ {% if something
19
+ HAPPY DAY
20
+ {% endif %}
21
+ TEMPLATE
22
+ LiquidValidator::Validator.new(template).valid?.must_equal false
23
+ end
24
+ end
25
+
26
+ describe "#errors" do
27
+ it "returns an empty array if the template has no errors" do
28
+ template = <<-TEMPLATE
29
+ {% if something %}
30
+ HAPPY DAY
31
+ {% endif %}
32
+ TEMPLATE
33
+ LiquidValidator::Validator.new(template).errors.must_equal []
34
+ end
35
+
36
+ it "returns an an array of the errors in the template" do
37
+ template = <<-TEMPLATE
38
+ {% if something
39
+ HAPPY DAY
40
+ {% endif %}
41
+ TEMPLATE
42
+ LiquidValidator::Validator.new(template).errors.must_equal ["Tag '{%' was not properly terminated with regexp: /\\%\\}/ "]
43
+ end
44
+ end
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid-validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy W. Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Liquid template validator
56
+ email:
57
+ - jeremy.w.rowe@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/liquid-validator.rb
69
+ - lib/liquid-validator/validator.rb
70
+ - lib/liquid-validator/version.rb
71
+ - liquid-validator.gemspec
72
+ - test/liquid_validator_test.rb
73
+ homepage: https://github.com/jeremywrowe/liquid-validator
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Validates template strings that are consumed when creating a liquid template.
97
+ It is simple, that is the point.
98
+ test_files:
99
+ - test/liquid_validator_test.rb