higml 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ higml
4
4
  Overview
5
5
  --------
6
6
 
7
- Higml is a terse format for converting an input hash to an output hash.
7
+ Higml is a concise format for "cascading configuration" - it uses cascading rules to create an output hash from an input hash.
8
8
 
9
9
  Example Higml and input:
10
10
 
@@ -30,7 +30,7 @@ This output is produced:
30
30
  :filter_terms => ... #depends on value of "filter_terms" method in given context
31
31
  }
32
32
 
33
- To get a better understand of _what_ Higml does, go through spec/higml_spec.rb and the corresponding .higml files in spec/fixtures.
33
+ To get a better understandung of _what_ Higml does, go through spec/higml_spec.rb and the corresponding .higml files in spec/fixtures.
34
34
 
35
35
  Why would you want to use it? The original use case was generating a json object for analytics. The json object had different fields and values depending on what section of the site and individual page were being viewed. When viewing a profile, the json might be
36
36
 
@@ -46,7 +46,7 @@ whereas search might look like
46
46
  section: "Search"
47
47
  }
48
48
 
49
- The actual json was much more complicated, containing about 20 keys. Writing the mapping between input and output in higml allowed my coworkers and I to quickly understand what the json would be for a given page, or why the json was the way it was. Example .higml files can be found in /examples.
49
+ The actual json was much more complicated, containing about 20 keys. Writing the mapping between input and output in separate higml files (one for each Rails controller) allowed my coworkers and I to quickly understand what the json would be for a given page, or why the json was the way it was. Example .higml files can be found in /examples.
50
50
 
51
51
  Syntax
52
52
  ------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{higml}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Higginbotham"]
12
- s.date = %q{2010-12-23}
12
+ s.date = %q{2011-06-09}
13
13
  s.description = %q{Higml is a terse format for converting a static input hash to a dynamic output hash.}
14
14
  s.email = %q{daniel@flyingmachinestudios.com}
15
15
  s.extra_rdoc_files = [
@@ -8,9 +8,9 @@ require 'higml/value'
8
8
 
9
9
  module Higml
10
10
  class << self
11
- def values_for(input, selector_config, priority_map, mapper_context)
11
+ def values_for(input, selector_config, mapper_context = nil, priority_map = {})
12
12
  tree = tree_for_selector_config(selector_config)
13
- Higml::Applier.new(input, tree, priority_map, mapper_context).result
13
+ Higml::Applier.new(input, tree, mapper_context, priority_map).result
14
14
  end
15
15
 
16
16
  def tree_for_selector_config(selector_config)
@@ -1,6 +1,6 @@
1
1
  module Higml
2
2
  class Applier
3
- def initialize(input, tree, priority_map, mapper_context)
3
+ def initialize(input, tree, mapper_context = nil, priority_map = {})
4
4
  @input = input
5
5
  @tree = tree
6
6
  @mapper_context = mapper_context
@@ -31,6 +31,8 @@ module Higml
31
31
  next if priority_keys.include? value.key
32
32
  if value.static?
33
33
  @result[value.key] = value.raw_value
34
+ elsif @mapper_context.nil?
35
+ raise ArgumentError, "you're trying to evaluate code without providing a context"
34
36
  else
35
37
  @result[value.key] = @mapper_context.instance_eval(value.raw_value)
36
38
  end
@@ -11,7 +11,7 @@ describe "HIGML integration" do
11
11
 
12
12
  it "should return the final values using input, higml filename, priority values" do
13
13
  priority_map = {:keywords => "tongue paper"}
14
- values = Higml.values_for(@input, 'search.higml', priority_map, @mapper_context)
14
+ values = Higml.values_for(@input, 'search.higml', @mapper_context, priority_map)
15
15
 
16
16
  values.should == {
17
17
  :channel => "Search",
@@ -23,7 +23,7 @@ describe "HIGML integration" do
23
23
 
24
24
  it "should allow you to use an existing tree instead of an sc filename" do
25
25
  tree = Higml::Parser.new(File.read(File.join(Higml.config.higml_directory, 'search.higml'))).to_tree
26
- values = Higml.values_for(@input, tree, {}, @mapper_context)
26
+ values = Higml.values_for(@input, tree, @mapper_context)
27
27
 
28
28
  values.should == {
29
29
  :channel => "Search",
@@ -32,4 +32,12 @@ describe "HIGML integration" do
32
32
  :filter_terms => @mapper_context.filter_terms
33
33
  }
34
34
  end
35
+
36
+ it "should work ok without mapper context or priority map" do
37
+ lambda{Higml.values_for({:action => "new"}, 'search.higml')}.should_not raise_error
38
+ end
39
+
40
+ it "should raise an error if applying a rule which requires a context, where none is provided" do
41
+ lambda{Higml.values_for({:action => "show", :keywords => "what"}, 'search.higml')}.should raise_error
42
+ end
35
43
  end
@@ -12,7 +12,7 @@ describe "Higml::Applier" do
12
12
  priority_map = {:keywords => "tongue paper"}
13
13
  mapper_context = Context.new
14
14
 
15
- values = Higml::Applier.new(input, tree, priority_map, mapper_context).result
15
+ values = Higml::Applier.new(input, tree, mapper_context, priority_map).result
16
16
 
17
17
  values.should == {
18
18
  :channel => "Search",
@@ -38,7 +38,7 @@ describe "Higml::Applier" do
38
38
  priority_map = {}
39
39
 
40
40
  mapper_context = Context.new
41
- Higml::Applier.new(input_group_1, tree, priority_map, mapper_context).result.should == {:filter => "filtered!"}
42
- Higml::Applier.new(input_group_2, tree, priority_map, mapper_context).result.should == {:filter => "filtered!"}
41
+ Higml::Applier.new(input_group_1, tree, mapper_context, priority_map).result.should == {:filter => "filtered!"}
42
+ Higml::Applier.new(input_group_2, tree, mapper_context, priority_map).result.should == {:filter => "filtered!"}
43
43
  end
44
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: higml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Higginbotham
@@ -15,14 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-23 00:00:00 -05:00
18
+ date: 2011-06-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :development
24
- name: rspec
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ">="
@@ -33,12 +30,12 @@ dependencies:
33
30
  - 3
34
31
  - 0
35
32
  version: 1.3.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
33
+ name: rspec
38
34
  prerelease: false
39
35
  type: :development
40
- name: bundler
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
42
39
  none: false
43
40
  requirements:
44
41
  - - ~>
@@ -49,12 +46,12 @@ dependencies:
49
46
  - 0
50
47
  - 0
51
48
  version: 1.0.0
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
49
+ name: bundler
54
50
  prerelease: false
55
51
  type: :development
56
- name: jeweler
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
58
55
  none: false
59
56
  requirements:
60
57
  - - ~>
@@ -65,12 +62,12 @@ dependencies:
65
62
  - 5
66
63
  - 2
67
64
  version: 1.5.2
68
- requirement: *id003
69
- - !ruby/object:Gem::Dependency
65
+ name: jeweler
70
66
  prerelease: false
71
67
  type: :development
72
- name: rcov
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: &id004 !ruby/object:Gem::Requirement
74
71
  none: false
75
72
  requirements:
76
73
  - - ">="
@@ -79,7 +76,10 @@ dependencies:
79
76
  segments:
80
77
  - 0
81
78
  version: "0"
82
- requirement: *id004
79
+ name: rcov
80
+ prerelease: false
81
+ type: :development
82
+ version_requirements: *id004
83
83
  description: Higml is a terse format for converting a static input hash to a dynamic output hash.
84
84
  email: daniel@flyingmachinestudios.com
85
85
  executables: []