cml 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +33 -0
  4. data/README.rdoc +13 -3
  5. data/Rakefile +9 -49
  6. data/cml.gemspec +23 -125
  7. data/lib/cml/converters/jsawesome.rb +3 -3
  8. data/lib/cml/gold.rb +12 -7
  9. data/lib/cml/liquid_filters.rb +4 -0
  10. data/lib/cml/logic.rb +424 -0
  11. data/lib/cml/logic_tree/graph.rb +107 -0
  12. data/lib/cml/logic_tree/solver.rb +43 -0
  13. data/lib/cml/parser.rb +47 -7
  14. data/lib/cml/tag.rb +42 -21
  15. data/lib/cml/tags/checkbox.rb +14 -4
  16. data/lib/cml/tags/checkboxes.rb +4 -0
  17. data/lib/cml/tags/group.rb +4 -0
  18. data/lib/cml/tags/hours.rb +263 -0
  19. data/lib/cml/tags/iterate.rb +4 -0
  20. data/lib/cml/tags/meta.rb +4 -0
  21. data/lib/cml/tags/option.rb +4 -0
  22. data/lib/cml/tags/radio.rb +13 -4
  23. data/lib/cml/tags/radios.rb +4 -0
  24. data/lib/cml/tags/ratings.rb +9 -1
  25. data/lib/cml/tags/search.rb +8 -2
  26. data/lib/cml/tags/select.rb +6 -2
  27. data/lib/cml/tags/taxonomy.rb +148 -0
  28. data/lib/cml/tags/thumb.rb +4 -0
  29. data/lib/cml/tags/unknown.rb +4 -0
  30. data/lib/cml/version.rb +3 -0
  31. data/lib/cml.rb +3 -0
  32. data/spec/converters/jsawesome_spec.rb +0 -9
  33. data/spec/fixtures/logic_broken.cml +5 -0
  34. data/spec/fixtures/logic_circular.cml +5 -0
  35. data/spec/fixtures/logic_grouped.cml +7 -0
  36. data/spec/fixtures/logic_nested.cml +7 -0
  37. data/spec/fixtures/logic_none.cml +7 -0
  38. data/spec/fixtures/logic_not_nested.cml +7 -0
  39. data/spec/liquid_filter_spec.rb +19 -0
  40. data/spec/logic_depends_on_spec.rb +242 -0
  41. data/spec/logic_spec.rb +207 -0
  42. data/spec/logic_tree_graph_spec.rb +465 -0
  43. data/spec/logic_tree_solver_spec.rb +58 -0
  44. data/spec/meta_spec.rb +12 -2
  45. data/spec/show_data_spec.rb +3 -2
  46. data/spec/spec_helper.rb +22 -6
  47. data/spec/tags/checkboxes_spec.rb +2 -2
  48. data/spec/tags/group_spec.rb +5 -5
  49. data/spec/tags/hours_spec.rb +404 -0
  50. data/spec/tags/radios_spec.rb +2 -2
  51. data/spec/tags/ratings_spec.rb +1 -1
  52. data/spec/tags/select_spec.rb +45 -0
  53. data/spec/tags/tag_spec.rb +25 -0
  54. data/spec/tags/taxonomy_spec.rb +112 -0
  55. data/spec/validation_spec.rb +52 -0
  56. metadata +112 -17
  57. data/VERSION +0 -1
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cml.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cml (1.23.0)
5
+ json
6
+ liquid (>= 2.0.0)
7
+ nokogiri (>= 1.4.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.2)
13
+ json (1.7.6)
14
+ liquid (2.5.0)
15
+ nokogiri (1.5.9)
16
+ rake (10.0.4)
17
+ rspec (2.13.0)
18
+ rspec-core (~> 2.13.0)
19
+ rspec-expectations (~> 2.13.0)
20
+ rspec-mocks (~> 2.13.0)
21
+ rspec-core (2.13.1)
22
+ rspec-expectations (2.13.0)
23
+ diff-lcs (>= 1.1.3, < 2.0)
24
+ rspec-mocks (2.13.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.3)
31
+ cml!
32
+ rake
33
+ rspec (~> 2.0)
data/README.rdoc CHANGED
@@ -1,6 +1,16 @@
1
- = cml
1
+ = CML
2
2
 
3
- Description goes here.
3
+ A.K.A. JSAwesome 2.0: Electric Boogaloo
4
+
5
+ To refresh CML gem in local builder:
6
+
7
+ rake refresh_builder
8
+
9
+ General release process:
10
+
11
+ # run and pass specs
12
+ rake version:bump:patch|minor|major
13
+ rake release
4
14
 
5
15
  == Note on Patches/Pull Requests
6
16
 
@@ -15,4 +25,4 @@ Description goes here.
15
25
 
16
26
  == Copyright
17
27
 
18
- Copyright (c) 2009 Chris Van Pelt. See LICENSE for details.
28
+ Copyright (c) 2011 Chris Van Pelt. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,56 +1,16 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'rspec/core/rake_task'
3
4
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "cml"
8
- gem.summary = "CML is CrowdFlower Markup Language"
9
- gem.description = "CML let's you easily create form elements and custom interfaces for the CrowdFlower Croud Labor platform"
10
- gem.email = "vanpelt@doloreslabs.com"
11
- gem.homepage = "http://github.com/dolores/cml"
12
- gem.authors = ["Chris Van Pelt"]
13
- gem.add_dependency 'liquid', '>= 2.0.0'
14
- gem.add_dependency 'nokogiri', '>= 1.4.2'
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
-
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
- end
21
-
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_opts = ["--format", "specdoc"]
26
- spec.spec_files = FileList['spec/**/*_spec.rb']
27
- end
28
-
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
34
-
35
- task :refresh_builder => [:build] do
36
- cp "pkg/cml-#{File.read("VERSION").strip}.gem", "../builder/gems/cache/"
37
- rm_rf "../builder/gems/gems/cml-#{File.read("VERSION").strip}/"
38
- `cd ../builder && bin/thor merb:gem:redeploy`
39
- end
5
+ RSpec::Core::RakeTask.new(:spec)
40
6
 
41
7
  task :default => :spec
42
8
 
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- if File.exist?('VERSION.yml')
46
- config = YAML.load(File.read('VERSION.yml'))
47
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
48
- else
49
- version = ""
50
- end
51
-
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "cml #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
9
+ task :refresh_builder => [:build] do
10
+ builder_dir = ENV['BUILDER_DIR'] || '../builder'
11
+ cp "cml.gemspec", "#{builder_dir}/vendor/bundle/ruby/1.8/specifications/cml-#{File.read("VERSION").strip}.gemspec"
12
+ cp "pkg/cml-#{File.read("VERSION").strip}.gem", "#{builder_dir}/vendor/bundle/ruby/1.8/cache/"
13
+ rm_rf "#{builder_dir}/vendor/bundle/ruby/1.8/gems/cml-#{File.read("VERSION").strip}/"
14
+ mkdir "#{builder_dir}/vendor/bundle/ruby/1.8/gems/cml-#{File.read("VERSION").strip}"
15
+ cp_r ".", "#{builder_dir}/vendor/bundle/ruby/1.8/gems/cml-#{File.read("VERSION").strip}/"
56
16
  end
data/cml.gemspec CHANGED
@@ -1,129 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cml/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{cml}
8
- s.version = "1.4.2"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cml"
8
+ spec.version = CML::VERSION
9
+ spec.authors = ["Chris Van Pelt"]
10
+ spec.email = ["vanpelt@doloreslabs.com"]
11
+ spec.description = %q{CML let's you easily create form elements and custom interfaces for the CrowdFlower Croud Labor platform}
12
+ spec.summary = %q{CML is CrowdFlower Markup Language}
13
+ spec.homepage = "https://github.com/dolores/cml"
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Chris Van Pelt"]
12
- s.date = %q{2011-02-28}
13
- s.description = %q{CML let's you easily create form elements and custom interfaces for the CrowdFlower Croud Labor platform}
14
- s.email = %q{vanpelt@doloreslabs.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "cml.gemspec",
27
- "lib/cml.rb",
28
- "lib/cml/converters/jsawesome.rb",
29
- "lib/cml/gold.rb",
30
- "lib/cml/liquid_filters.rb",
31
- "lib/cml/parser.rb",
32
- "lib/cml/tag.rb",
33
- "lib/cml/tags/checkbox.rb",
34
- "lib/cml/tags/checkboxes.rb",
35
- "lib/cml/tags/group.rb",
36
- "lib/cml/tags/hidden.rb",
37
- "lib/cml/tags/iterate.rb",
38
- "lib/cml/tags/meta.rb",
39
- "lib/cml/tags/multiple_text.rb",
40
- "lib/cml/tags/option.rb",
41
- "lib/cml/tags/radio.rb",
42
- "lib/cml/tags/radios.rb",
43
- "lib/cml/tags/ratings.rb",
44
- "lib/cml/tags/search.rb",
45
- "lib/cml/tags/select.rb",
46
- "lib/cml/tags/text.rb",
47
- "lib/cml/tags/textarea.rb",
48
- "lib/cml/tags/thumb.rb",
49
- "lib/cml/tags/unknown.rb",
50
- "spec/complex_spec.rb",
51
- "spec/converters/jsawesome_spec.rb",
52
- "spec/fixtures/complex.cml",
53
- "spec/fixtures/html.cml",
54
- "spec/fixtures/invalid.cml",
55
- "spec/fixtures/script-style.cml",
56
- "spec/fixtures/segfault.cml",
57
- "spec/gold_spec.rb",
58
- "spec/meta_spec.rb",
59
- "spec/normalize_spec.rb",
60
- "spec/show_data_spec.rb",
61
- "spec/sorta_match.rb",
62
- "spec/spec_helper.rb",
63
- "spec/tags/checkbox_spec.rb",
64
- "spec/tags/checkboxes_spec.rb",
65
- "spec/tags/group_spec.rb",
66
- "spec/tags/hidden_spec.rb",
67
- "spec/tags/iterate_spec.rb",
68
- "spec/tags/meta_spec.rb",
69
- "spec/tags/multiple_text_spec.rb",
70
- "spec/tags/radios_spec.rb",
71
- "spec/tags/ratings_spec.rb",
72
- "spec/tags/search_spec.rb",
73
- "spec/tags/select_spec.rb",
74
- "spec/tags/tag_spec.rb",
75
- "spec/tags/text_spec.rb",
76
- "spec/tags/textarea_spec.rb",
77
- "spec/tags/thumb_spec.rb",
78
- "spec/tags/unknown_spec.rb",
79
- "spec/validation_spec.rb"
80
- ]
81
- s.homepage = %q{http://github.com/dolores/cml}
82
- s.rdoc_options = ["--charset=UTF-8"]
83
- s.require_paths = ["lib"]
84
- s.rubygems_version = %q{1.3.7}
85
- s.summary = %q{CML is CrowdFlower Markup Language}
86
- s.test_files = [
87
- "spec/complex_spec.rb",
88
- "spec/converters/jsawesome_spec.rb",
89
- "spec/gold_spec.rb",
90
- "spec/meta_spec.rb",
91
- "spec/normalize_spec.rb",
92
- "spec/show_data_spec.rb",
93
- "spec/sorta_match.rb",
94
- "spec/spec_helper.rb",
95
- "spec/tags/checkbox_spec.rb",
96
- "spec/tags/checkboxes_spec.rb",
97
- "spec/tags/group_spec.rb",
98
- "spec/tags/hidden_spec.rb",
99
- "spec/tags/iterate_spec.rb",
100
- "spec/tags/meta_spec.rb",
101
- "spec/tags/multiple_text_spec.rb",
102
- "spec/tags/radios_spec.rb",
103
- "spec/tags/ratings_spec.rb",
104
- "spec/tags/search_spec.rb",
105
- "spec/tags/select_spec.rb",
106
- "spec/tags/tag_spec.rb",
107
- "spec/tags/text_spec.rb",
108
- "spec/tags/textarea_spec.rb",
109
- "spec/tags/thumb_spec.rb",
110
- "spec/tags/unknown_spec.rb",
111
- "spec/validation_spec.rb"
112
- ]
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"]
113
20
 
114
- if s.respond_to? :specification_version then
115
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
116
- s.specification_version = 3
117
-
118
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
119
- s.add_runtime_dependency(%q<liquid>, [">= 2.0.0"])
120
- s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.2"])
121
- else
122
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
123
- s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
124
- end
125
- else
126
- s.add_dependency(%q<liquid>, [">= 2.0.0"])
127
- s.add_dependency(%q<nokogiri>, [">= 1.4.2"])
128
- end
21
+ spec.add_dependency "liquid", ">= 2.0.0"
22
+ spec.add_dependency "nokogiri", ">= 1.4.2"
23
+ spec.add_dependency "json"
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 2.0"
129
27
  end
@@ -28,7 +28,7 @@ module CML
28
28
  end
29
29
 
30
30
  def label(k)
31
- k = k.sub(/^[_#*^~]?\+?/,'')
31
+ k = k.to_s.sub(/^[_#*^~]?\+?/,'')
32
32
  l = @labels[k]
33
33
  label = l.is_a?(Hash) ? l["label"] : l if l
34
34
  label ||= k.capitalize.gsub(/_/,' ')
@@ -38,7 +38,7 @@ module CML
38
38
  val = Array(val)
39
39
  return nil unless val[0]
40
40
  parts = val[0].split("|")
41
- key = parts[0].sub(/^[_#*^~]?\+?/,'')
41
+ key = parts[0].to_s.sub(/^[_#*^~]?\+?/,'')
42
42
  label = label(parts[0])
43
43
  parts << key if label != key.capitalize.gsub(/_/,' ') || opts[:meta]
44
44
  attrs = opts[:meta] ? [] : ["label=\"#{label}\""]
@@ -69,7 +69,7 @@ module CML
69
69
  select_default = @labels['{}'] || "Choose Category"
70
70
  cml = case v
71
71
  #a select tag or group of radios/checkboxes
72
- when Array:
72
+ when Array
73
73
  if(k =~ /^[^_]/)
74
74
  if $~[0] == "*"
75
75
  parent = "radios"
data/lib/cml/gold.rb CHANGED
@@ -1,24 +1,29 @@
1
1
  module CML
2
2
  class Gold
3
- Attrs = ["exact","strict","regex","structured","matcher"]
4
- attr_reader *(Attrs + [:src, :name])
3
+ Attrs = ["exact","strict","regex","structured","matcher","superset"]
4
+ ATTR_ALIASES = {'subset' => 'strict'}
5
+ attr_reader *(Attrs + [:src, :name, :tag])
5
6
 
6
7
  def initialize(tag, gold)
7
- @name = tag.name(false)
8
+ @tag = tag
9
+ @name = @tag.name(false)
8
10
  @src = (gold.attributes["gold"] || gold.attributes["src"]).to_s
9
11
  @src = "#{@name}_gold" if @src =~ /^(true|\s*)$/
10
- Attrs.each do |attribute|
12
+ (Attrs + ATTR_ALIASES.keys).each do |attribute|
11
13
  if a = gold.attributes[attribute]
14
+ attribute = ATTR_ALIASES[attribute] || attribute
12
15
  value = case attribute
13
- when "regex": [a.to_s, gold.attributes["flags"].to_s, gold.attributes["no_escape"].to_s]
14
- when "matcher": a.to_s
16
+ when "regex"
17
+ [a.to_s, gold.attributes["flags"].to_s, gold.attributes["no_escape"].to_s]
18
+ when "matcher"
19
+ a.to_s
15
20
  else
16
21
  a.to_s == "true"
17
22
  end
18
23
  instance_variable_set "@#{attribute}", value
19
24
  end
20
25
  end
21
- @structured = true if tag.iterating?
26
+ @structured = true if @tag.iterating?
22
27
  end
23
28
 
24
29
  def to_hash
@@ -3,6 +3,10 @@ module CML
3
3
  def to_json(input)
4
4
  input.to_json
5
5
  end
6
+
7
+ def random(input)
8
+ rand(input.to_i)
9
+ end
6
10
  end
7
11
 
8
12
  class LiquidHash < Hash