elf_manifesto 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +6 -0
  3. data/.rvmrc +1 -0
  4. data/Elf_Manifesto.gemspec +43 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +29 -0
  7. data/Rakefile +1 -0
  8. data/bin/manifesto +131 -0
  9. data/coverage/.resultset.json +75 -0
  10. data/coverage/assets/0.5.3/app.js +88 -0
  11. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  25. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  26. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  27. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  28. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  29. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  30. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  31. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  32. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  33. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  34. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  35. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  36. data/coverage/assets/0.5.3/highlight.css +129 -0
  37. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  38. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  39. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  40. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  41. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  42. data/coverage/assets/0.5.3/loading.gif +0 -0
  43. data/coverage/assets/0.5.3/magnify.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  51. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  52. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  53. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  54. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  55. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  56. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  57. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  58. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  59. data/coverage/index.html +155 -0
  60. data/features/create_a_manifest.feature +75 -0
  61. data/features/step_definitions/create_a_manifest_steps.rb +13 -0
  62. data/features/step_definitions/use_built_in_templates_steps.rb +42 -0
  63. data/features/support/env.rb +13 -0
  64. data/features/use_built_in_templates.feature +78 -0
  65. data/features/use_config_files.feature +31 -0
  66. data/lib/.DS_Store +0 -0
  67. data/lib/Elf_Manifesto/version.rb +4 -0
  68. data/lib/Elf_Manifesto.rb +5 -0
  69. data/lib/elf_manifesto/manifest_maker.rb +61 -0
  70. data/lib/templates/imsmanifest.xml.mustache +55 -0
  71. data/lib/templates/simple.mustache +15 -0
  72. data/readme.md +110 -0
  73. data/spec/lib/elf_manifesto/manifest_maker_spec.rb +154 -0
  74. data/spec/spec_helper.rb +5 -0
  75. metadata +268 -0
@@ -0,0 +1,78 @@
1
+ Feature: Using built-in Templates
2
+
3
+ As a console user
4
+ I want to use a range of built in templates
5
+ So that I can create a range of manifests quickly
6
+
7
+ Scenario: listing available templates
8
+ Given a library of templates: simple.mustache scorm.tmp simple.tmp example.tmp
9
+ When I run `manifesto list templates`
10
+ Then the output should contain "Available Templates:"
11
+ And the output should not contain "lib/templates"
12
+ And the output should contain "scorm.tmp"
13
+ And the output should contain "simple.tmp"
14
+ And the output should contain "example.tmp"
15
+
16
+ Scenario: 'list' command alias
17
+ Given a library of templates: simple.mustache scorm.tmp simple.tmp example.tmp
18
+ When I run `manifesto list`
19
+ Then the output should contain "Available Templates:"
20
+ And the output should not contain "lib/templates"
21
+ And the output should contain "scorm.tmp"
22
+ And the output should contain "simple.tmp"
23
+ And the output should contain "example.tmp"
24
+
25
+ Scenario: showing the contents of a built in template
26
+ Given a library of templates: test.tmp
27
+ When I run `manifesto show template test`
28
+ Then the output should contain "{{#groups}}"
29
+
30
+ Scenario: 'show' command alias
31
+ Given a library of templates: test.tmp
32
+ When I run `manifesto show test`
33
+ Then the output should contain "{{#groups}}"
34
+
35
+ Scenario: requesting the contents of a non-existent template
36
+ Given a library of templates: test.tmp
37
+ When I run `manifesto show template duffer`
38
+ Then the exit status should not be 0
39
+ And the output should contain "Template does not exist: duffer"
40
+
41
+
42
+ Scenario: rendering with a built in template
43
+ Given a library of templates: tester.mustache
44
+ And a collection of files: page1.html page2.html page3.html
45
+ When I run `manifesto --sample_template tester '**/*.html'`
46
+ Then the output should contain "group1 (**/*.html):"
47
+ And the output should contain "page1.html"
48
+ And the output should contain "page2.html"
49
+ And the output should contain "page3.html"
50
+ And the exit status should be 0
51
+
52
+ Scenario Outline: providing a bad sample template name
53
+ Given a library of templates: tester.mustache
54
+ When I run `<command>`
55
+ Then the exit status should not be 0
56
+ And the output should contain "<result>"
57
+
58
+ Scenarios: Bad built in template selection
59
+ | command | result |
60
+ | manifesto --sample_template duff '*.*' | Bad template selection: duff |
61
+
62
+ Scenarios: Bad template path
63
+ | command | result |
64
+ | manifesto --template duff '*.*' | Bad template selection: duff |
65
+
66
+ Scenario: using an '_' prefix in the template name to load a built in template
67
+ Given a library of templates: tester.mustache
68
+ And a collection of files: page1.html page2.html page3.html
69
+ When I run `manifesto --template _tester '**/*.html'`
70
+ Then the output should contain "group1 (**/*.html):"
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
@@ -0,0 +1,31 @@
1
+ Feature: Using a config file with manifesto
2
+
3
+ As a manifesto user
4
+ I want to provide a config file
5
+ So that I can re-use a set of config options and I don't need to write horribly long commands in the terminal
6
+
7
+ Scenario: Using a config file to run a built in template
8
+ Given a file named "manifesto.config" with:
9
+ """
10
+ {
11
+ template: "_simple",
12
+ globs: ["learning_objects/**/*.html", "assets*/**/*.* ", "js/**/*.*"],
13
+ props: {
14
+ manifest_id:'com.hmeelearning.eh',
15
+ org_id: 'hmeeh',sco_id: 'ID72c02ada-df91-41ca-a440-15062a4683c0',
16
+ org_name: 'Experience Hyundai',
17
+ sco_name: 'Module 6 - Quiz',
18
+ sco_pass_score: 0.7
19
+ }
20
+ }
21
+ """
22
+ And a library of templates: simple.mustache
23
+ When I run `manifesto -c manifesto.config`
24
+ Then the output should contain "group1"
25
+ And the output should contain "sco_name"
26
+ And the output should contain "Module 6"
27
+
28
+
29
+
30
+
31
+
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,4 @@
1
+ module ElfManifesto
2
+ # Tools for creating manifests from file collections and Mustache Templates
3
+ VERSION = "1.0.0"
4
+ end
@@ -0,0 +1,5 @@
1
+ require "elf_manifesto/version"
2
+
3
+ module ElfManifesto
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'mustache'
2
+
3
+ module ElfManifesto
4
+
5
+ class ManifestMaker
6
+
7
+ attr_reader :file_groups, :result
8
+ # *Args*
9
+ # * ops:: +Hash+ -> Hash of options
10
+ #
11
+ # ops = {
12
+ # template: 'path/to/template.file',
13
+ # properties: { prop1: 'foobar' },
14
+ # globs: ['*.*', '*.jpg'],
15
+ # }
16
+ #
17
+ # ElfManifesto::ManifestMaker.new(ops)
18
+ #
19
+ # [+template+] +String+ -> template file to load
20
+ # [+properties+] +Hash+ -> arbitrary properties to supply to template
21
+ # [+globs+] +Array+ -> list of file globs to evaluate
22
+ def initialize(ops)
23
+ @file_groups = get_file_groups(ops[:globs]) # evaluate the globs and create the file groups
24
+ @file_groups[:props] = ops[:props] unless ops[:props].nil?
25
+ template_file = File.open ops[:template], 'rb'
26
+ @template = template_file.read
27
+ @result = Mustache.render @template, @file_groups
28
+ message = ""
29
+ pos = 1
30
+ # puts "#{message}\n\n\n"
31
+ puts @result
32
+ end
33
+
34
+ private
35
+ # get_file_groups
36
+ # Evaluate the globs array and populate the file_groups object.
37
+ # It's the file_groups object that is used to populate the template.
38
+ #
39
+ # * *Args* :
40
+ # globs - +Array+ -> list of strings to use as file searches
41
+ # * *Returns* :
42
+ # - dictionary of file group arrays
43
+ def get_file_groups globs
44
+ pos = 1
45
+ file_groups = { groups: [] }
46
+
47
+ globs.each do |glob|
48
+ # e.g { group1: { path: '*.*', files: [file1, file2]} }
49
+ group_name = "group#{pos}"
50
+ files = Dir.glob(glob)
51
+ file_group_object = { name: group_name, path: glob, files: files }
52
+ file_groups[group_name.to_sym] = file_group_object
53
+ file_groups[:groups].push file_group_object
54
+ pos += 1
55
+ end
56
+ file_groups
57
+ end
58
+
59
+
60
+ end
61
+ end
@@ -0,0 +1,55 @@
1
+ <manifest identifier="{{props.manifest_id}}" version="1.0" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" xmlns:adlseq="http://www.adlnet.org/xsd/adlseq_v1p3" xmlns:adlnav="http://www.adlnet.org/xsd/adlnav_v1p3" xmlns:imsss="http://www.imsglobal.org/xsd/imsss" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2
+ <metadata>
3
+ <schema>ADL SCORM</schema>
4
+ <schemaversion>2004 3rd Edition</schemaversion>
5
+ </metadata>
6
+ <organizations default="{{props.org_id}}">
7
+ <organization identifier="{{props.org_id}}">
8
+ <title>{{props.org_name}}</title>
9
+ <!-- identifier is a guid --> <!-- identifierref is "sco_" + guid -->
10
+ <item identifier="{{props.sco_id}}" identifierref="sco_{{props.sco_id}}">
11
+ <title>{{props.sco_name}}</title>
12
+ <imsss:sequencing>
13
+ <imsss:objectives>
14
+ <imsss:primaryObjective objectiveID="PRIMOBJ" satisfiedByMeasure="true">
15
+ <imsss:minNormalizedMeasure>{{props.sco_pass_score}}</imsss:minNormalizedMeasure>
16
+ </imsss:primaryObjective>
17
+ </imsss:objectives>
18
+ <imsss:deliveryControls completionSetByContent="true" objectiveSetByContent="true" />
19
+ </imsss:sequencing>
20
+ </item>
21
+ <imsss:sequencing>
22
+ <imsss:controlMode choiceExit="true" flow="true" />
23
+ </imsss:sequencing>
24
+ </organization>
25
+ </organizations>
26
+ <resources>
27
+ <!-- identifier is "sco_" + guid (used on line10) -->
28
+ <resource identifier="sco_{{props.sco_id}}" adlcp:scormType="sco" href="index.html" type="webcontent">
29
+ <!-- include reference to the SCO file itself -->
30
+ <file href="index.html" />
31
+ <!-- group1: page files here. glob example "learning_objects/**/*.html" -->
32
+ {{#group1.files}}
33
+ <file href="{{.}}" />
34
+ {{/group1.files}}
35
+ <!-- group2: List all assets used in the SCO. glob "ASSETS_FOLDER*/**/*.* "-->
36
+ {{#group2.files}}
37
+ <file href="{{.}}" />
38
+ {{/group2.files}}
39
+ <dependency identifierref="COMMON_ASSETS" />
40
+ <dependency identifierref="THINQI_SYS" />
41
+ </resource>
42
+ <resource identifier="COMMON_ASSETS" type="webcontent" adlcp:scormType="asset">
43
+ <!-- group3: List all assets used in package. glob "COMMON_ASSETS*/**/*.* "-->
44
+ {{#group3.files}}
45
+ <file href="{{.}}" />
46
+ {{/group3.files}}
47
+ </resource>
48
+ <resource identifier="THINQI_SYS" type="webcontent" adlcp:scormType="asset">
49
+ <!-- group4: List all CI/Framework files here. glob example "js/**/*.*"-->
50
+ {{#group4.files}}
51
+ <file href="{{.}}" />
52
+ {{/group4.files}}
53
+ </resource>
54
+ </resources>
55
+ </manifest>
@@ -0,0 +1,15 @@
1
+ Matched Groups:
2
+ {{#groups}}
3
+ {{name}} ({{path}}): {{#files}}{{.}} {{/files}}
4
+ {{/groups}}
5
+
6
+ Each file glob passed in creates a new file group. Each group has a name, path and files property. Reference specific file groups by their name which is 'group' followed by the group number. So 'group1' for the first group etc.
7
+
8
+ So the first group's path glob is -> {{group1.path}}
9
+ And the files matching it are:
10
+ {{#group1.files}}
11
+ {{.}}
12
+ {{/group1.files}}
13
+
14
+ {{#props}}Properties{{/props}}
15
+ {{props}}
data/readme.md ADDED
@@ -0,0 +1,110 @@
1
+ # ELF Manifesto #
2
+
3
+ A gem for creating file manifests from Mustache templates
4
+
5
+ ## Usage ##
6
+
7
+ Run from the command line. Provide a template file and pass in a number of file globs ("*.jpg", or "images/*.*" for example). Each file collection returned from the each glob will be used to populate the given template.
8
+
9
+ e.g.
10
+
11
+ `manifesto create template_file.mustache '*.*' '*.jpg' 'pages/*.html'`
12
+
13
+ ('create' is the default command so you can leave it out if you like. 'manifesto template_filed.mustache '*.*' '*.jpg' 'pages/*.html')
14
+
15
+ This will load the file 'template_file.mustache' and treat it as a [mustache][mustache] template. (Go [here][mustache] for more info). The file extension doesn't matter. I've used .mustache just to make the point.
16
+
17
+ At the end of the command you can provide any number of space delimited strings that will be evaluated as file globs and used to search the file system from your current location. In this example
18
+
19
+ * '*.*' returns paths to all files in the current directory
20
+ * '*.jpg' returns paths to all jpgs in the current directory
21
+ * 'pages/*.html' returns paths to all html files in the pages directory
22
+
23
+ I'm sure you get the idea...
24
+
25
+ Each collection of paths are added to a numbered group and made available in the template. In our example, group1 corresponds to '*.*', group2 to '*.jpg' and so on. By referencing these groups in a mustache template you can build manifest files populated with all the file paths you need.
26
+
27
+ ## Saving the manifest ##
28
+
29
+ The manifest is output to the console, so you can save it by copying or directing the output to a file.
30
+
31
+ `manifesto create template_file.mustache '*.*' '*.jpg' 'pages/*.html' > manifest.json`
32
+ will render the template and save it in manifest.json.
33
+
34
+ ---
35
+
36
+ ## Passing Arbitrary Properties ##
37
+
38
+ Use the --properties or -p switch to pass in a string to be evaluated as a property hash
39
+
40
+ `manifesto create template_file.mustache -p "{ :name => 'foo', :surname => 'bar' }" '*.*' '*.jpg' 'pages/*.html'`
41
+
42
+ will make the {{props.name}} and {{props.surname}} available in the template. (N.B. Ruby syntax for the hash)
43
+
44
+
45
+ ---
46
+ ## Built in templates ##
47
+
48
+ There are a few built in templates available. Use
49
+
50
+ `manifesto list`
51
+
52
+ ...to list them.
53
+
54
+ * simple.mustache - simple template for playing around and getting your globs right
55
+ * imsmanifest.xml.mustache - For creating SCORM manifests. If you don't know what they are then you don't need 'em :)
56
+
57
+ ### Displaying a template ###
58
+
59
+ If you want to view a built in template you can use
60
+
61
+ `manifesto show template_name`
62
+
63
+ (you only need to use the start of the template name for the sake of brevity. So `manifesto show ims` would do the trick).
64
+
65
+ If you want to base your own templates on one of the built in ones then you can pipe it out to a file and then edit it.
66
+
67
+ `manifesto show template_name > my_template.mustache`
68
+
69
+ To use a built in template use the -s switch with the template name
70
+
71
+ `manifesto -s ims "*.*"`
72
+
73
+ or just prefix the template name with an underscore
74
+
75
+ `manifesto -m ims "*.*"`
76
+
77
+ ---
78
+ ## Using config files ##
79
+
80
+ Typing long string representations of property hashes into the command line is 'orrible. So you can use config files instead. Like this one...
81
+
82
+ > {
83
+ > template: "_imsmanifest",
84
+ > globs: ["pages/**/*.html", "assets*/**/*.* ", "js/**/*.*"],
85
+ > props: {
86
+ > manifest_id:'com.learning.eh',
87
+ > org_id: 'ID72c02ada-df91-41ca-a440-15062a4683c0',
88
+ > package_name: 'Module 6',
89
+ > }
90
+ > }
91
+
92
+ * template: path to a template relative to the current working directory
93
+ * globs: array of file searches
94
+ * props: arbitrary properties to reference in the templates
95
+
96
+ To use a config file use the -c switch
97
+
98
+ `manifesto -c path_to_config.file`
99
+
100
+ N.B. Config files are evaluated as Ruby, just so you know
101
+
102
+ ---
103
+ # TODO #
104
+
105
+ * Support registration of new templates
106
+ * Add some simple template helpers
107
+ * GUID creator
108
+ * Commander -h seems to fail on windows machines. Doh!
109
+
110
+ [mustache]: http://mustache.github.com/mustache.5.html
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+ require "elf_manifesto/manifest_maker"
3
+ require 'mustache'
4
+
5
+ all_files = ['file1.txt', 'file2.', 'file3.txt', 'image1.jpg', 'image2.jpg']
6
+ image_files = ['image1.jpg', 'image2.jpg']
7
+ txt_files = ['file1.txt', 'file2.', 'file3.txt']
8
+
9
+ describe "Creating a manifest." do
10
+ before(:each) do
11
+
12
+ end
13
+
14
+ describe "Evaluating file groups." do
15
+ it "should accept a single file group" do
16
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
17
+ mock_input_file_read "duff.template", simple_template()
18
+ # manifesto = ElfManifesto::ManifestMaker.new('duff.template', {}, ['*.*'])
19
+ ops = {
20
+ template: 'duff.template',
21
+ globs: ['*.*']
22
+ }
23
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
24
+ end
25
+
26
+ describe "Gathering file collections." do
27
+ it "should evaluate a single glob string" do
28
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
29
+ mock_input_file_read "duff.template", simple_template()
30
+ ops = {
31
+ template: 'duff.template',
32
+ globs: ['*.*']
33
+ }
34
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
35
+ manifesto.file_groups[:group1][:files].should eq all_files
36
+ end
37
+
38
+ it "should evaluate multiple glob strings" do
39
+ Dir.should_receive(:glob).with('*.jpg').and_return(image_files)
40
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
41
+ Dir.should_receive(:glob).with('*.txt').and_return(txt_files)
42
+ mock_input_file_read "duff.template", simple_template()
43
+
44
+ ops = {
45
+ template: 'duff.template',
46
+ globs: ['*.*', '*.jpg', '*.txt']
47
+ }
48
+
49
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
50
+ manifesto.file_groups[:group1][:files].should eq all_files
51
+ manifesto.file_groups[:group2][:files].should eq image_files
52
+ manifesto.file_groups[:group3][:files].should eq txt_files
53
+ end
54
+
55
+ describe "gathering information about the groups" do
56
+ before(:each) do
57
+ Dir.should_receive(:glob).with('*.jpg').and_return(image_files)
58
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
59
+ Dir.should_receive(:glob).with('*.txt').and_return(txt_files)
60
+ mock_input_file_read "duff.template", simple_template()
61
+
62
+ ops = {
63
+ template: 'duff.template',
64
+ globs: ['*.*', '*.jpg', '*.txt']
65
+ }
66
+ @subject = ElfManifesto::ManifestMaker.new(ops)
67
+ end
68
+
69
+ it "should store a list of the groups" do
70
+ @subject.file_groups[:groups].should have(3).items
71
+ end
72
+ end
73
+
74
+ describe "Storing arbitrary properties" do
75
+ it "should make any property hashes provided available to the template" do
76
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
77
+ mock_input_file_read "duff.template", simple_template()
78
+ ops = {
79
+ template: 'duff.template',
80
+ globs: ['*.*'],
81
+ props: { name: 'foobar' }
82
+ }
83
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
84
+ manifesto.file_groups[:props][:name].should eq 'foobar'
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "Rendering the template" do
90
+ before(:each) do
91
+ # mock file expectations
92
+ Dir.should_receive(:glob).with('*.jpg').and_return(image_files)
93
+ Dir.should_receive(:glob).with('*.*').and_return(all_files)
94
+ Dir.should_receive(:glob).with('*.txt').and_return(txt_files)
95
+ end
96
+
97
+ it "should load a template" do
98
+ mock_input_file_read "simple.mustache", simple_template()
99
+ Mustache.stub(:render)
100
+ ops = {
101
+ template: 'simple.mustache',
102
+ globs: ['*.*', '*.jpg', '*.txt']
103
+ }
104
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
105
+ end
106
+
107
+ describe "with Mustache" do
108
+ before(:each) do
109
+ mock_input_file_read "simple.mustache", simple_template()
110
+ Mustache.should_receive(:render).and_return("The Result")
111
+ end
112
+
113
+ it "should use mustache to render the template" do
114
+ ops = {
115
+ template: 'simple.mustache',
116
+ globs: ['*.*', '*.jpg', '*.txt']
117
+ }
118
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
119
+ end
120
+
121
+ it "should store the result" do
122
+ ops = {
123
+ template: 'simple.mustache',
124
+ globs: ['*.*', '*.jpg', '*.txt']
125
+ }
126
+ manifesto = ElfManifesto::ManifestMaker.new(ops)
127
+ manifesto.result.should eq 'The Result'
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def mock_input_file_read file_name, contents = ""
139
+ # Set expectations
140
+ @stuntfile = double()
141
+ @stuntfile.should_receive(:read).and_return(contents)
142
+ File.should_receive(:open).with(file_name,"rb").and_return(@stuntfile)
143
+ end
144
+
145
+ def simple_template
146
+ <<-eos
147
+ {{#.}}
148
+ Files Matching {{path}}
149
+ {{name}}
150
+ {{/.}}
151
+ eos
152
+ end
153
+
154
+
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_group "CLI", "bin"
4
+ add_group "Workers", "lib/elf_manifesto"
5
+ end