higml 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/VERSION +1 -1
- data/higml.gemspec +2 -2
- data/lib/higml.rb +2 -2
- data/lib/higml/applier.rb +3 -1
- data/spec/higml_spec.rb +10 -2
- data/spec/lib/higml/applier_spec.rb +3 -3
- metadata +21 -21
data/README.markdown
CHANGED
@@ -4,7 +4,7 @@ higml
|
|
4
4
|
Overview
|
5
5
|
--------
|
6
6
|
|
7
|
-
Higml is a
|
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
|
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.
|
1
|
+
0.0.1
|
data/higml.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{higml}
|
8
|
-
s.version = "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{
|
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 = [
|
data/lib/higml.rb
CHANGED
@@ -8,9 +8,9 @@ require 'higml/value'
|
|
8
8
|
|
9
9
|
module Higml
|
10
10
|
class << self
|
11
|
-
def values_for(input, selector_config,
|
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,
|
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)
|
data/lib/higml/applier.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Higml
|
2
2
|
class Applier
|
3
|
-
def initialize(input, tree,
|
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
|
data/spec/higml_spec.rb
CHANGED
@@ -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',
|
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,
|
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,
|
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,
|
42
|
-
Higml::Applier.new(input_group_2, tree,
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 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:
|
18
|
+
date: 2011-06-09 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
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
|
-
|
37
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
name: rspec
|
38
34
|
prerelease: false
|
39
35
|
type: :development
|
40
|
-
|
41
|
-
|
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
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
54
50
|
prerelease: false
|
55
51
|
type: :development
|
56
|
-
|
57
|
-
|
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
|
-
|
69
|
-
- !ruby/object:Gem::Dependency
|
65
|
+
name: jeweler
|
70
66
|
prerelease: false
|
71
67
|
type: :development
|
72
|
-
|
73
|
-
|
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
|
-
|
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: []
|