geb 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +56 -12
  4. data/lib/geb/commands/server.rb +3 -2
  5. data/lib/geb/config.rb +88 -0
  6. data/lib/geb/defaults.rb +2 -2
  7. data/lib/geb/page.rb +35 -3
  8. data/lib/geb/samples/basic/assets/css/site.css +41 -2
  9. data/lib/geb/samples/basic/geb.config.yml +19 -3
  10. data/lib/geb/samples/basic/index.html +24 -1
  11. data/lib/geb/samples/basic/shared/partials/_footer.html +4 -0
  12. data/lib/geb/samples/basic/shared/partials/_geb.html +26 -0
  13. data/lib/geb/samples/basic/shared/partials/_header.html +9 -0
  14. data/lib/geb/samples/bootstrap_jquery/assets/css/site.css +68 -1
  15. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_1.html +83 -25
  16. data/lib/geb/samples/bootstrap_jquery/blog/index.html +39 -6
  17. data/lib/geb/samples/bootstrap_jquery/geb.config.yml +20 -3
  18. data/lib/geb/samples/bootstrap_jquery/index.html +252 -2
  19. data/lib/geb/samples/bootstrap_jquery/page.html +24 -2
  20. data/lib/geb/samples/bootstrap_jquery/shared/partials/_footer.html +2 -0
  21. data/lib/geb/samples/bootstrap_jquery/shared/partials/_geb.html +26 -0
  22. data/lib/geb/samples/bootstrap_jquery/shared/partials/_header.html +25 -0
  23. data/lib/geb/samples/bootstrap_jquery/shared/partials/_meta_tags.html +1 -1
  24. data/lib/geb/samples/bootstrap_jquery/shared/templates/_blog_post.html +19 -0
  25. data/lib/geb/samples/bootstrap_jquery/site.webmanifest +1 -1
  26. data/lib/geb/samples/geb.config.yml +17 -0
  27. data/lib/geb/server.rb +12 -6
  28. data/lib/geb/site/build.rb +73 -61
  29. data/lib/geb/site/release.rb +23 -28
  30. data/lib/geb/site/remote.rb +1 -1
  31. data/lib/geb/site/template.rb +6 -0
  32. data/lib/geb/site.rb +7 -0
  33. data/lib/geb/template.rb +1 -0
  34. data/lib/geb/utilities.rb +1 -1
  35. data/lib/geb.rb +1 -1
  36. data/test/api tests/test_cli.rb +1 -1
  37. data/test/api tests/test_config.rb +132 -0
  38. data/test/api tests/test_page.rb +88 -4
  39. data/test/api tests/test_server.rb +96 -32
  40. data/test/api tests/test_site.rb +131 -31
  41. data/test/command tests/test_geb_build.rb +2 -2
  42. data/test/command tests/test_geb_release.rb +6 -8
  43. data/test/command tests/test_geb_server.rb +21 -0
  44. metadata +4 -4
  45. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_2.html +0 -35
  46. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_3.html +0 -35
data/lib/geb/server.rb CHANGED
@@ -22,11 +22,13 @@ module Geb
22
22
  # @param site [Geb::Site] the site instance to serve
23
23
  # @param port [Integer] the port to run the server on
24
24
  # @param auto_build [Boolean] whether to start the file watcher
25
- def initialize(site, port, auto_build)
25
+ # @param debug [Boolean] whether to enable full output during site rebuild
26
+ def initialize(site, port, auto_build, debug)
26
27
 
27
28
  # set the site and port
28
29
  @site = site
29
30
  @port = port
31
+ @debug = debug
30
32
 
31
33
  # get the http server instance and file watcher if auto_build is set
32
34
  @http_server = get_http_server()
@@ -73,7 +75,7 @@ module Geb
73
75
  # Create a new WEBrick server
74
76
  server = WEBrick::HTTPServer.new(
75
77
  Port: @port,
76
- DocumentRoot: @site.get_site_output_directory()
78
+ DocumentRoot: @site.get_site_local_output_directory()
77
79
  ) # WEBrick::HTTPServer.new
78
80
 
79
81
  Geb.log "Server running on http://localhost:#{server.config[:Port]}/"
@@ -104,8 +106,12 @@ module Geb
104
106
  # attempt to rebuild the site, log any errors but do not stop watching
105
107
  begin
106
108
 
107
- # rebuild the site, suppress log output
108
- Geb.no_log { @site.build() }
109
+ # rebuild the site, suppress log output if deubg is not set
110
+ if @debug
111
+ @site.build()
112
+ else
113
+ Geb.no_log { @site.build() }
114
+ end # if else
109
115
 
110
116
  rescue Geb::Error => e
111
117
  Geb.log "\nError rebuilding site: #{e.message}"
@@ -118,8 +124,8 @@ module Geb
118
124
  end # Listen.to(site.site_path) do |modified, added, removed|
119
125
 
120
126
  # set ignore the output and release directories, cleanup the paths and make them relative to the site path
121
- ignore_output_dir = @site.get_site_output_directory().gsub(@site.site_path, '').gsub(/\A\W+/, '')
122
- ignore_release_dir = @site.get_site_release_directory().gsub(@site.site_path, '').gsub(/\A\W+/, '')
127
+ ignore_output_dir = @site.get_site_local_output_directory().gsub(@site.site_path, '').gsub(/\A\W+/, '')
128
+ ignore_release_dir = @site.get_site_release_output_directory().gsub(@site.site_path, '').gsub(/\A\W+/, '')
123
129
 
124
130
  Geb.log "Watching for changes in [#{@site.site_path}]"
125
131
  Geb.log "Ignoring [#{ignore_output_dir}]"
@@ -24,6 +24,7 @@ module Geb
24
24
  end # class FailedToOutputSite < Geb::Error
25
25
 
26
26
  # build the site
27
+ # @raise SiteNotLoaded if the site is not loaded
27
28
  def build
28
29
 
29
30
  # make sure the site is laoded, if not, raise an error
@@ -36,52 +37,6 @@ module Geb
36
37
 
37
38
  end # def build
38
39
 
39
- # build the assets for the site
40
- # @raise SiteNotLoaded if the site is not loaded
41
- def build_assets
42
-
43
- # make sure the site is laoded, if not, raise an error
44
- raise SiteNotLoadedError.new("Could not build assets.") unless @loaded
45
-
46
- # get the site asset and output assets directory
47
- site_assets_dir = get_site_assets_directory()
48
- outout_assets_dir = File.join(get_site_output_directory(), site_assets_dir.gsub(@site_path, ""))
49
-
50
- Geb.log "Building assets for #{site_name}\n\n"
51
-
52
- # step through all the asset files and copy them to the output directory
53
- Dir.glob("#{site_assets_dir}/**/*").each do |asset_file|
54
-
55
- # skip directories
56
- next if File.directory?(asset_file)
57
-
58
- # get the relative path of the asset file and the destination path
59
- asset_relative_path = asset_file.gsub(site_assets_dir, "")
60
- asset_full_destination_path = File.join(outout_assets_dir, asset_relative_path)
61
-
62
- # check if the destination asset file exists
63
- if File.exist?(asset_full_destination_path)
64
-
65
- Geb.log " - skipping asset: #{asset_relative_path}"
66
-
67
- else
68
-
69
- Geb.log " - processing asset: #{asset_relative_path}"
70
-
71
- # create the output directory for the asset file
72
- output_dir = File.join(outout_assets_dir, File.dirname(asset_relative_path))
73
- FileUtils.mkdir_p(output_dir)
74
-
75
- # copy the asset file to the output directory
76
- FileUtils.cp(asset_file, output_dir)
77
-
78
- end # if else
79
-
80
- end # Dir.glob
81
- Geb.log "\nDone building assets for #{site_name}"
82
-
83
- end # def build_assets
84
-
85
40
  # build the pages for the site
86
41
  # @raise SiteNotLoaded if the site is not loaded
87
42
  def build_pages
@@ -93,13 +48,13 @@ module Geb
93
48
  Geb::Template.expire_cache
94
49
  Geb::Partial.expire_cache
95
50
 
96
- # find all HTML files in the site path that don't start with an underscore, with extention .html and .htm
51
+ # find all pages to build
97
52
  page_files = get_page_files(@site_path,
98
53
  @site_config.page_extensions(),
99
54
  @site_config.template_and_partial_identifier(),
100
- [get_site_output_directory(), get_site_release_directory()])
55
+ [get_site_local_output_directory(), get_site_release_output_directory()])
101
56
 
102
- Geb.log "Building #{page_files.length} pages for #{site_name}"
57
+ Geb.log "Building #{page_files.length} #{site_name} pages #{@releasing ? 'for release' : 'locally'}"
103
58
 
104
59
  # create a temporary directory
105
60
  Dir.mktmpdir do |tmp_dir|
@@ -117,14 +72,17 @@ module Geb
117
72
  # attempt to write the site to the output directory
118
73
  begin
119
74
 
75
+ # get the destination directory for the site output, depending on the release flag
76
+ destination_directory = @releasing ? get_site_release_output_directory() : get_site_local_output_directory()
77
+
120
78
  # clear the output directory
121
- Geb.log_start "Clearing site output folder #{get_site_output_directory()} ... "
122
- clear_site_output_directory()
79
+ Geb.log_start "Clearing site output folder #{destination_directory} ... "
80
+ clear_site_output_directory(destination_directory)
123
81
  Geb.log "done."
124
82
 
125
83
  # copy the files to the output directory
126
- Geb.log_start "Outputting site to #{get_site_output_directory()} ... "
127
- output_site(tmp_dir)
84
+ Geb.log_start "Outputting site to #{destination_directory} ... "
85
+ output_site(tmp_dir, destination_directory)
128
86
  Geb.log "done."
129
87
 
130
88
  rescue => e
@@ -135,11 +93,60 @@ module Geb
135
93
 
136
94
  end # def build_pages
137
95
 
138
- # get the site output directory
96
+ # build the assets for the site
97
+ # @raise SiteNotLoaded if the site is not loaded
98
+ def build_assets
99
+
100
+ # make sure the site is laoded, if not, raise an error
101
+ raise SiteNotLoadedError.new("Could not build assets.") unless @loaded
102
+
103
+ # get the destination directory for the site output, depending on the release flag
104
+ destination_directory = @releasing ? get_site_release_output_directory() : get_site_local_output_directory()
105
+
106
+ # get the site asset and output assets directory
107
+ site_assets_dir = get_site_assets_directory()
108
+ output_assets_dir = File.join(destination_directory, site_assets_dir.gsub(@site_path, ""))
109
+
110
+ Geb.log "Building #{site_name} assets #{@releasing ? 'for release' : 'locally'}\n\n"
111
+
112
+ # step through all the asset files and copy them to the output directory
113
+ Dir.glob("#{site_assets_dir}/**/*").each do |asset_file|
114
+
115
+ # skip directories
116
+ next if File.directory?(asset_file)
117
+
118
+ # get the relative path of the asset file and the destination path
119
+ asset_relative_path = asset_file.gsub(site_assets_dir, "")
120
+ asset_full_destination_path = File.join(output_assets_dir, asset_relative_path)
121
+
122
+ # check if the destination asset file exists
123
+ if File.exist?(asset_full_destination_path)
124
+
125
+ Geb.log " - skipping asset: #{asset_relative_path}"
126
+
127
+ else
128
+
129
+ Geb.log " - processing asset: #{asset_relative_path}"
130
+
131
+ # create the output directory for the asset file
132
+ output_dir = File.join(output_assets_dir, File.dirname(asset_relative_path))
133
+ FileUtils.mkdir_p(output_dir)
134
+
135
+ # copy the asset file to the output directory
136
+ FileUtils.cp(asset_file, output_dir)
137
+
138
+ end # if else
139
+
140
+ end # Dir.glob
141
+ Geb.log "\nDone building assets for #{site_name}"
142
+
143
+ end # def build_assets
144
+
145
+ # get the site local output directory
139
146
  # @return [String] the site output directory
140
- def get_site_output_directory
147
+ def get_site_local_output_directory
141
148
  return File.join(@site_path, @site_config.output_dir, Geb::Defaults::LOCAL_OUTPUT_DIR)
142
- end # def get_site_output_directory
149
+ end # def get_site_local_output_directory
143
150
 
144
151
  # get the page files in the specified path, with specified extentions and ignoring files that match the pattern
145
152
  # @param path [String] the path to the files
@@ -150,6 +157,9 @@ module Geb
150
157
  # @note the ignore_files_exp and ignore_directories are used to ignore files that are not pages
151
158
  def get_page_files(path, exts = Geb::Defaults::PAGE_EXTENSIONS, ignore_files_exp = Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER, ignore_directories = [])
152
159
 
160
+ # make sure every page extention specified starts with a dot
161
+ exts.map! { |ext| ext.start_with?('.') ? ext : ".#{ext}" }
162
+
153
163
  # get all files in the path with the specified extentions
154
164
  files = Dir.glob("#{path}/**/*{#{exts.join(',')}}")
155
165
 
@@ -165,17 +175,19 @@ module Geb
165
175
  end # def get_page_files
166
176
 
167
177
  # clear the site output directory
178
+ # @param output_directory [String] the output directory to clear
168
179
  # @return [Nil]
169
- def clear_site_output_directory
170
- FileUtils.rm_rf(Dir.glob("#{get_site_output_directory()}/*"))
180
+ def clear_site_output_directory(output_directory)
181
+ FileUtils.rm_rf(Dir.glob("#{output_directory}/*"))
171
182
  end # def clear_site_output_directory
172
183
 
173
184
  # output the site from specified directory to the output directory. The specified directory is typically
174
185
  # a temporary directory where the site has been built.
175
- # @param output_dir [String] the directory to output
186
+ # @param source_dir [String] the source directory
187
+ # @param output_dir [String] the output directory
176
188
  # @return [Nil]
177
- def output_site(output_dir)
178
- FileUtils.cp_r("#{output_dir}/.", get_site_output_directory())
189
+ def output_site(source_dir, output_dir)
190
+ FileUtils.cp_r("#{source_dir}/.", output_dir)
179
191
  end # def output_site
180
192
 
181
193
  # get the site assets directory
@@ -13,24 +13,31 @@ module Geb
13
13
  class Site
14
14
  module Release
15
15
 
16
+ class SiteReleasingError < Geb::Error
17
+ MESSAGE = "Site is already releasing.".freeze
18
+ def initialize(e = ""); super(e, MESSAGE); end
19
+ end # class SiteReleasingError < Geb::Error
20
+
16
21
  # release the site
22
+ # @raise SiteNotLoadedError if the site is not loaded
17
23
  def release
18
24
 
19
- # build the site first
20
- build();
25
+ # make sure the site is laoded, if not, raise an error
26
+ raise Geb::Site::SiteNotLoadedError.new("Could not release the site.") unless @loaded
21
27
 
22
- # get the site local and release directory
23
- site_release_directory = get_site_release_directory()
28
+ # make sure the site is not already releasing, to prevent recursive releases
29
+ raise Geb::Site::SiteReleasingError.new if @releasing
24
30
 
25
- # clear the output directory
26
- Geb.log_start "Clearing site release folder #{site_release_directory} ... "
27
- clear_site_release_directory()
28
- Geb.log "done."
31
+ # set the site to releasing
32
+ @releasing = true
33
+
34
+ # build the site
35
+ build();
29
36
 
30
- # copy the files to the output directory
31
- Geb.log_start "Releasing site to #{site_release_directory} ... "
32
- copy_site_to_release_directory()
33
- Geb.log "done."
37
+ ensure
38
+
39
+ # set the site to not releasing
40
+ @releasing = false
34
41
 
35
42
  end # def release
36
43
 
@@ -40,29 +47,17 @@ module Geb
40
47
  return File.join(@site_path, @site_config.output_dir, Geb::Defaults::RELEASE_OUTPUT_DIR, Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME)
41
48
  end # def get_template_archive_release_path
42
49
 
43
- # get the site release directory
50
+ # get the site release output directory
44
51
  # @return [String] the site release directory
45
- def get_site_release_directory
52
+ def get_site_release_output_directory
46
53
  return File.join(@site_path, @site_config.output_dir, Geb::Defaults::RELEASE_OUTPUT_DIR)
47
- end # def get_site_release_directory
48
-
49
- # clear the site release directory
50
- # @return [Nil]
51
- def clear_site_release_directory
52
- FileUtils.rm_rf(Dir.glob("#{get_site_release_directory()}/*"))
53
- end # def clear_site_release_directory
54
-
55
- # output the site from local output to release directory.
56
- # @return [Nil]
57
- def copy_site_to_release_directory
58
- FileUtils.cp_r("#{get_site_output_directory()}/.", get_site_release_directory())
59
- end # def output_site
54
+ end # def get_site_release_output_directory
60
55
 
61
56
  # check if the site has been released.
62
57
  # The site is considered released if the release directory exists and is not empty.
63
58
  # @return [Boolean] true if the site has been released, false otherwise
64
59
  def released?
65
- return Dir.exist?(get_site_release_directory()) && !Dir.empty?(get_site_release_directory())
60
+ return Dir.exist?(get_site_release_output_directory()) && !Dir.empty?(get_site_release_output_directory())
66
61
  end # def released?
67
62
 
68
63
  end # module Build
@@ -86,7 +86,7 @@ module Geb
86
86
 
87
87
  # build up the command arguments
88
88
  command_exclude_pattern = '*.DS_Store'
89
- command_source_directory = File.join(get_site_release_directory, '/')
89
+ command_source_directory = File.join(get_site_release_output_directory(), '/')
90
90
  command_remote_uri = @site_config.remote_uri + ":" + @site_config.remote_path
91
91
 
92
92
  # build the rsync command
@@ -68,6 +68,7 @@ module Geb
68
68
  # @raise InvalidTemplateSpecification if the template paths are not specified
69
69
  # @raise InvalidTemplateSpecification if the resolved template paths are empty
70
70
  # @raise InvalidTemplateSpecification if the template archive cannot be created
71
+ # @note template will be bundled with the geb.config.yml file, so the site can be re-created from the template
71
72
  def bundle_template
72
73
 
73
74
  # raise an error if the site is not loaded
@@ -91,6 +92,11 @@ module Geb
91
92
  Geb.copy_paths_to_directory(@site_path, resolved_template_paths, tmp_archive_directory)
92
93
  Geb.log "Done copying directories and files to the template archive directory."
93
94
 
95
+ # create a geb config file in the temporary directory
96
+ Geb.log_start "Generating geb.config.yml in the template archive directory ... "
97
+ @site_config.generate_config_file(tmp_archive_directory)
98
+ Geb.log "done."
99
+
94
100
  # create a template archive with files from the temporary directory into the release directory
95
101
  output_archive_filename = File.join(@site_path, @site_config.output_dir, Geb::Defaults::RELEASE_OUTPUT_DIR, Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME)
96
102
  Geb.log_start "Creating template archive in [#{output_archive_filename}] ... "
data/lib/geb/site.rb CHANGED
@@ -53,6 +53,12 @@ module Geb
53
53
  # @return [Boolean] true if the site is loaded
54
54
  attr_reader :loaded
55
55
 
56
+ # @!attribute [r] releasing
57
+ # @return [Boolean] true if the site is releasing
58
+ # @note this is used to prevent recursive releases and to ensure site variables are correct
59
+ # @note this is set to true when the site is being released and reset to false when the release is done
60
+ attr_reader :releasing
61
+
56
62
  # @!attribute [r] pages
57
63
  # @return [Hash] the site pages to process
58
64
  attr_reader :pages
@@ -63,6 +69,7 @@ module Geb
63
69
 
64
70
  @validated = false
65
71
  @loaded = false
72
+ @releasing = false
66
73
  @site_path = nil
67
74
  @template_path = nil
68
75
  @pages = {}
data/lib/geb/template.rb CHANGED
@@ -18,6 +18,7 @@ require 'fileutils'
18
18
  module Geb
19
19
  class Template
20
20
 
21
+ # template, section and insert tag match patterns
21
22
  TEMPLATE_PATTERN = /<% template: (.*?) %>/
22
23
  SECTION_PATTERN = /<% start: (.*?) %>(.*?)<% end: \1 %>/m
23
24
  INSERT_PATTERN = /<%= insert: (.*?) %>/
data/lib/geb/utilities.rb CHANGED
@@ -87,7 +87,7 @@ module Geb
87
87
  destination_file_path = File.join(destination_path, relative_template_path)
88
88
 
89
89
  # ensure the destination directory exists
90
- FileUtils.mkdir_p(File.dirname(destination_path))
90
+ FileUtils.mkdir_p(File.dirname(destination_file_path))
91
91
 
92
92
  # copy the resolved template path to the destination path
93
93
  if File.directory?(path)
data/lib/geb.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  module Geb
15
15
 
16
16
  # define the version of the gem
17
- VERSION = "0.1.11"
17
+ VERSION = "0.1.12"
18
18
 
19
19
  end # module Geb
20
20
 
@@ -131,7 +131,7 @@ class TestCli < Minitest::Test
131
131
  refute_nil Geb::CLI::Commands::Server.method_defined?(:options)
132
132
  refute_empty Geb::CLI::Commands::Server.options, "Server command should have options."
133
133
 
134
- assert_cli_option Geb::CLI::Commands::Server, :port, :int, 0
134
+ assert_cli_option Geb::CLI::Commands::Server, :port, :int, nil
135
135
  assert_cli_option Geb::CLI::Commands::Server, :skip_build, :boolean, false
136
136
 
137
137
  end # test "that geb has a server command"
@@ -327,4 +327,136 @@ class TestConfig < Minitest::Test
327
327
 
328
328
  end # test "that the template paths are returned as config value if set"
329
329
 
330
+ test "that generate config file creates a new config file" do
331
+
332
+ site = Geb::Site.new
333
+ site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
334
+
335
+ site.instance_variable_set :@site_path, site_path
336
+
337
+ config = Geb::Config.new(site)
338
+
339
+ refute_empty config.instance_variable_get(:@config)
340
+
341
+ Dir.mktmpdir do |tmp_dir|
342
+
343
+ config.generate_config_file(tmp_dir)
344
+
345
+ assert File.exist?(File.join(tmp_dir, Geb::Defaults::SITE_CONFIG_FILENAME))
346
+
347
+ new_generated_config = YAML.load_file(File.join(tmp_dir, Geb::Defaults::SITE_CONFIG_FILENAME))
348
+
349
+ refute_empty new_generated_config
350
+
351
+ assert_nil new_generated_config['site_name']
352
+ assert_nil new_generated_config['remote_uri']
353
+ assert_nil new_generated_config['remote_path']
354
+
355
+ end # Dir.mktmpdir
356
+
357
+ end # test "that generate config file creates a new config file"
358
+
359
+ test "that generate config file raises an error if the destination directory doesn't exist" do
360
+
361
+ site = Geb::Site.new
362
+ site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
363
+
364
+ site.instance_variable_set :@site_path, site_path
365
+
366
+ config = Geb::Config.new(site)
367
+
368
+ refute_empty config.instance_variable_get(:@config)
369
+
370
+ error = assert_raises(Geb::Config::DestinationDirMissing) do
371
+ config.generate_config_file("fake_dir")
372
+ end
373
+
374
+ assert_includes error.message, "Specified directory [fake_dir] missing."
375
+
376
+ end # test "that generate config file raises an error if the destination directory doesn't exist"
377
+
378
+ test "that generate config file raises an error if the config file already exists" do
379
+
380
+ site = Geb::Site.new
381
+ site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
382
+
383
+ site.instance_variable_set :@site_path, site_path
384
+
385
+ config = Geb::Config.new(site)
386
+
387
+ refute_empty config.instance_variable_get(:@config)
388
+
389
+ Dir.mktmpdir do |tmp_dir|
390
+
391
+ File.open(File.join(tmp_dir, Geb::Defaults::SITE_CONFIG_FILENAME), 'w') { |f| f.write("test") }
392
+
393
+ error = assert_raises(Geb::Config::ConfigAlreadyExists) do
394
+ config.generate_config_file(tmp_dir)
395
+ end
396
+
397
+ assert_includes error.message, "Specified directory [#{tmp_dir}] already has geb config."
398
+
399
+ end # Dir.mktmpdir
400
+
401
+ end # test "that generate config file raises an error if the config file already exists"
402
+
403
+ test "that generate config sucessfully generates all configuration fields" do
404
+
405
+ site = Geb::Site.new
406
+ site_path = File.join(File.dirname(__FILE__), "..", "files", "test-site")
407
+
408
+ site.instance_variable_set :@site_path, site_path
409
+
410
+ config = Geb::Config.new(site)
411
+
412
+ refute_empty config.instance_variable_get(:@config)
413
+
414
+ test_config = {}
415
+ test_config['site_name'] = "test-site"
416
+ test_config['remote_uri'] = "https://primjer.hr"
417
+ test_config['remote_path'] = "/var/www/html"
418
+ test_config['local_port'] = 737373
419
+ test_config['output_dir'] = "publicni"
420
+ test_config['assets_dir'] = "assetsni"
421
+ test_config['page_extensions'] = [".erb", ".htm", ".php"]
422
+ test_config['template_paths'] = ["templates", "partials"]
423
+ test_config['template_and_partial_identifier'] = "erb"
424
+ test_config['site_variables'] = {
425
+ 'local' => {'site_name' => 'test-site', 'site_url' => 'http://localhost:737373', 'site_path' => '/var/www/html' },
426
+ 'release' => {'site_name' => 'test-site', 'site_url' => 'https://primjer.hr', 'site_path' => '/var/www/html' }
427
+ }
428
+
429
+ config.instance_variable_set :@config, test_config
430
+
431
+ Dir.mktmpdir do |tmp_dir|
432
+
433
+ config.generate_config_file(tmp_dir)
434
+
435
+ assert File.exist?(File.join(tmp_dir, Geb::Defaults::SITE_CONFIG_FILENAME))
436
+
437
+ new_generated_config = YAML.load_file(File.join(tmp_dir, Geb::Defaults::SITE_CONFIG_FILENAME))
438
+
439
+ refute_empty new_generated_config
440
+
441
+ assert_nil new_generated_config['site_name']
442
+ assert_nil new_generated_config['remote_uri']
443
+ assert_nil new_generated_config['remote_path']
444
+
445
+ assert_equal test_config['local_port'], new_generated_config['local_port']
446
+ assert_equal test_config['output_dir'], new_generated_config['output_dir']
447
+ assert_equal test_config['assets_dir'], new_generated_config['assets_dir']
448
+ assert_equal test_config['page_extensions'], new_generated_config['page_extensions']
449
+ assert_equal test_config['template_paths'], new_generated_config['template_paths']
450
+ assert_equal test_config['template_and_partial_identifier'], new_generated_config['template_and_partial_identifier']
451
+ assert_equal test_config['site_variables']['local'], new_generated_config['site_variables']['local']
452
+ refute_equal test_config['site_variables']['release'], new_generated_config['site_variables']['release']
453
+
454
+ assert_empty new_generated_config['site_variables']['release']['site_name']
455
+ assert_empty new_generated_config['site_variables']['release']['site_url']
456
+ assert_empty new_generated_config['site_variables']['release']['site_path']
457
+
458
+ end # Dir.mktmpdir
459
+
460
+ end # test "that generate config sucessfully generates all configuration fields"
461
+
330
462
  end # class TestConfig < Minitest::Test
@@ -76,17 +76,17 @@ class PageTest < Geb::ApiTest
76
76
  site = mock('site')
77
77
  site.stubs(:site_path).returns(Dir.pwd)
78
78
 
79
+ parse_sequence = sequence('parse_sequence')
79
80
  Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
80
- Geb::Page.any_instance.stubs(:parse_for_templates).returns(parsed_page_content)
81
- Geb::Page.any_instance.stubs(:parse_for_partials).returns(parsed_page_content)
81
+ Geb::Page.any_instance.stubs(:parse_for_templates).returns(parsed_page_content).once.in_sequence(parse_sequence)
82
+ Geb::Page.any_instance.stubs(:parse_for_partials).returns(parsed_page_content).once.in_sequence(parse_sequence)
83
+ Geb::Page.any_instance.stubs(:parse_for_site_variables).returns(parsed_page_content).once.in_sequence(parse_sequence)
82
84
  File.stubs(:read).returns(page_content)
83
85
 
84
86
  page = Geb::Page.new(site, page_path)
85
87
 
86
88
  assert_respond_to page, :parse
87
89
 
88
- page.parse
89
-
90
90
  assert_respond_to page, :parsed_content
91
91
  assert_equal page.parsed_content, parsed_page_content
92
92
  refute_equal page.parsed_content, page.content
@@ -204,6 +204,90 @@ class PageTest < Geb::ApiTest
204
204
 
205
205
  end # test "that page parse_for_partials method works"
206
206
 
207
+ test "that the parse_for_site_variables method works" do
208
+
209
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
210
+ site_name = "Some cool site"
211
+ page_title = "This is some ultra cool page title"
212
+ page_content = <<-PAGE
213
+ _{variable_1}_ _{variable_2}_ _{variable_3}_
214
+ <title>#{page_title}</title>
215
+ Find the _{page_title}_ here
216
+ _{page_relative_path}_
217
+ _{site_name}_
218
+ Geb version _{geb_version}_
219
+ PAGE
220
+
221
+ site_variables = { "variable_1" => "value_1", "variable_2" => "value_2" }
222
+
223
+ config = mock('config')
224
+ config.stubs(:get_site_variables).returns(site_variables)
225
+ config.stubs(:site_name).returns(site_name)
226
+
227
+ site = mock('site')
228
+ site.stubs(:site_path).returns(Dir.pwd)
229
+ site.stubs(:site_config).returns(config)
230
+
231
+ File.stubs(:read).returns(page_content)
232
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
233
+ Geb::Page.any_instance.stubs(:parse_for_templates).returns(page_content)
234
+ Geb::Page.any_instance.stubs(:parse_for_partials).returns(page_content)
235
+
236
+ page = Geb::Page.new(site, page_path)
237
+
238
+ output_content = page.parse_for_site_variables(page_content)
239
+
240
+ assert_includes output_content, "value_1"
241
+ assert_includes output_content, "value_2"
242
+ assert_includes output_content, "_{variable_3}_"
243
+ assert_includes output_content, site_name
244
+ assert_includes output_content, "Find the #{page_title} here"
245
+ assert_includes output_content, "Geb version #{Geb::VERSION}"
246
+ assert_includes output_content, page_path.gsub(Dir.pwd, "")
247
+
248
+ end # test "that the parse_for_site_variables method works"
249
+
250
+ test "that the parse_for_site_variables method works if site variables are not set" do
251
+
252
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
253
+ site_name = "Some cool site"
254
+ page_title = "This is some ultra cool page title"
255
+ page_content = <<-PAGE
256
+ _{variable_1}_ _{variable_2}_ _{variable_3}_
257
+ <title>#{page_title}</title>
258
+ _{site_name}_
259
+ _{page_relative_path}_
260
+ _{site_name}_
261
+ PAGE
262
+
263
+ site_variables = nil
264
+
265
+ config = mock('config')
266
+ config.stubs(:get_site_variables).returns(site_variables)
267
+ config.stubs(:site_name).returns(site_name)
268
+
269
+ site = mock('site')
270
+ site.stubs(:site_path).returns(Dir.pwd)
271
+ site.stubs(:site_config).returns(config)
272
+
273
+ File.stubs(:read).returns(page_content)
274
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
275
+ Geb::Page.any_instance.stubs(:parse_for_templates).returns(page_content)
276
+ Geb::Page.any_instance.stubs(:parse_for_partials).returns(page_content)
277
+
278
+ page = Geb::Page.new(site, page_path)
279
+
280
+ output_content = page.parse_for_site_variables(page_content)
281
+
282
+ assert_includes output_content, "_{variable_1}_"
283
+ assert_includes output_content, "_{variable_2}_"
284
+ assert_includes output_content, "_{variable_3}_"
285
+ assert_includes output_content, site_name
286
+ assert_includes output_content, " <title>#{page_title}</title>"
287
+ assert_includes output_content, page_path.gsub(Dir.pwd, "")
288
+
289
+ end # test "that the parse_for_site_variables method works if site variables are not set"
290
+
207
291
  test "that page build method works" do
208
292
 
209
293
  site_path = Dir.pwd