nanoc3 3.2.0a4 → 3.2.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/NEWS.md +20 -2
  2. data/README.md +7 -3
  3. data/bin/nanoc3 +1 -3
  4. data/lib/nanoc3.rb +1 -13
  5. data/lib/nanoc3/base/compilation/filter.rb +21 -0
  6. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +1 -3
  7. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +1 -1
  8. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -2
  9. data/lib/nanoc3/base/compilation/rules_collection.rb +37 -13
  10. data/lib/nanoc3/base/directed_graph.rb +3 -3
  11. data/lib/nanoc3/base/memoization.rb +6 -9
  12. data/lib/nanoc3/base/source_data/code_snippet.rb +2 -1
  13. data/lib/nanoc3/base/source_data/configuration.rb +7 -3
  14. data/lib/nanoc3/base/source_data/item.rb +52 -10
  15. data/lib/nanoc3/base/source_data/layout.rb +28 -1
  16. data/lib/nanoc3/base/source_data/site.rb +14 -3
  17. data/lib/nanoc3/cli.rb +98 -6
  18. data/lib/nanoc3/cli/{base.rb → command.rb} +117 -153
  19. data/lib/nanoc3/cli/commands/autocompile.rb +20 -48
  20. data/lib/nanoc3/cli/commands/compile.rb +32 -48
  21. data/lib/nanoc3/cli/commands/create_item.rb +21 -37
  22. data/lib/nanoc3/cli/commands/create_layout.rb +18 -36
  23. data/lib/nanoc3/cli/commands/create_site.rb +15 -34
  24. data/lib/nanoc3/cli/commands/debug.rb +17 -31
  25. data/lib/nanoc3/cli/commands/info.rb +14 -29
  26. data/lib/nanoc3/cli/commands/nanoc.rb +37 -0
  27. data/lib/nanoc3/cli/commands/update.rb +21 -44
  28. data/lib/nanoc3/cli/commands/view.rb +18 -44
  29. data/lib/nanoc3/cli/commands/watch.rb +16 -31
  30. data/lib/nanoc3/data_sources/filesystem.rb +25 -6
  31. data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
  32. data/lib/nanoc3/extra/auto_compiler.rb +1 -0
  33. data/lib/nanoc3/extra/file_proxy.rb +0 -1
  34. data/lib/nanoc3/filters.rb +2 -0
  35. data/lib/nanoc3/filters/asciidoc.rb +16 -36
  36. data/lib/nanoc3/filters/bluecloth.rb +2 -2
  37. data/lib/nanoc3/filters/coderay.rb +2 -2
  38. data/lib/nanoc3/filters/colorize_syntax.rb +18 -5
  39. data/lib/nanoc3/filters/erb.rb +2 -2
  40. data/lib/nanoc3/filters/erubis.rb +2 -2
  41. data/lib/nanoc3/filters/haml.rb +2 -2
  42. data/lib/nanoc3/filters/kramdown.rb +2 -2
  43. data/lib/nanoc3/filters/less.rb +32 -1
  44. data/lib/nanoc3/filters/markaby.rb +2 -2
  45. data/lib/nanoc3/filters/maruku.rb +2 -2
  46. data/lib/nanoc3/filters/mustache.rb +2 -2
  47. data/lib/nanoc3/filters/rainpress.rb +2 -2
  48. data/lib/nanoc3/filters/rdiscount.rb +4 -3
  49. data/lib/nanoc3/filters/rdoc.rb +10 -6
  50. data/lib/nanoc3/filters/redcarpet.rb +2 -2
  51. data/lib/nanoc3/filters/redcloth.rb +2 -2
  52. data/lib/nanoc3/filters/rubypants.rb +2 -2
  53. data/lib/nanoc3/filters/sass.rb +44 -52
  54. data/lib/nanoc3/filters/slim.rb +2 -2
  55. data/lib/nanoc3/filters/typogruby.rb +2 -2
  56. data/lib/nanoc3/filters/uglify_js.rb +42 -0
  57. data/nanoc3.gemspec +1 -1
  58. data/tasks/test.rake +6 -0
  59. data/test/base/core_ext/array_spec.rb +0 -2
  60. data/test/base/core_ext/hash_spec.rb +0 -2
  61. data/test/base/core_ext/pathname_spec.rb +0 -2
  62. data/test/base/core_ext/string_spec.rb +0 -2
  63. data/test/base/test_checksum_store.rb +0 -2
  64. data/test/base/test_code_snippet.rb +0 -2
  65. data/test/base/test_compiler.rb +2 -4
  66. data/test/base/test_compiler_dsl.rb +1 -3
  67. data/test/base/test_context.rb +0 -2
  68. data/test/base/test_data_source.rb +0 -2
  69. data/test/base/test_dependency_tracker.rb +0 -2
  70. data/test/base/test_directed_graph.rb +0 -2
  71. data/test/base/test_filter.rb +0 -2
  72. data/test/base/test_item.rb +19 -4
  73. data/test/base/test_item_rep.rb +0 -2
  74. data/test/base/test_layout.rb +19 -4
  75. data/test/base/test_memoization.rb +39 -2
  76. data/test/base/test_notification_center.rb +0 -2
  77. data/test/base/test_outdatedness_checker.rb +31 -2
  78. data/test/base/test_plugin.rb +0 -2
  79. data/test/base/test_rule.rb +0 -2
  80. data/test/base/test_rule_context.rb +0 -2
  81. data/test/base/test_site.rb +30 -3
  82. data/test/cli/commands/test_compile.rb +24 -3
  83. data/test/cli/commands/test_create_item.rb +5 -3
  84. data/test/cli/commands/test_create_layout.rb +4 -4
  85. data/test/cli/commands/test_create_site.rb +5 -5
  86. data/test/cli/commands/test_help.rb +3 -3
  87. data/test/cli/commands/test_info.rb +2 -3
  88. data/test/cli/commands/test_update.rb +0 -2
  89. data/test/cli/test_cli.rb +40 -0
  90. data/test/cli/test_logger.rb +0 -2
  91. data/test/data_sources/test_filesystem.rb +0 -2
  92. data/test/data_sources/test_filesystem_unified.rb +32 -58
  93. data/test/data_sources/test_filesystem_verbose.rb +0 -2
  94. data/test/extra/core_ext/test_enumerable.rb +0 -2
  95. data/test/extra/core_ext/test_time.rb +0 -2
  96. data/test/extra/deployers/test_rsync.rb +0 -2
  97. data/test/extra/test_auto_compiler.rb +5 -7
  98. data/test/extra/test_file_proxy.rb +0 -2
  99. data/test/extra/test_vcs.rb +0 -2
  100. data/test/extra/validators/test_links.rb +0 -2
  101. data/test/extra/validators/test_w3c.rb +0 -2
  102. data/test/filters/test_asciidoc.rb +0 -2
  103. data/test/filters/test_bluecloth.rb +0 -2
  104. data/test/filters/test_coderay.rb +0 -2
  105. data/test/filters/test_colorize_syntax.rb +49 -2
  106. data/test/filters/test_erb.rb +0 -2
  107. data/test/filters/test_erubis.rb +0 -2
  108. data/test/filters/test_haml.rb +0 -2
  109. data/test/filters/test_kramdown.rb +0 -2
  110. data/test/filters/test_less.rb +59 -5
  111. data/test/filters/test_markaby.rb +0 -2
  112. data/test/filters/test_maruku.rb +0 -2
  113. data/test/filters/test_mustache.rb +0 -2
  114. data/test/filters/test_rainpress.rb +0 -2
  115. data/test/filters/test_rdiscount.rb +0 -2
  116. data/test/filters/test_rdoc.rb +0 -2
  117. data/test/filters/test_redcarpet.rb +0 -2
  118. data/test/filters/test_redcloth.rb +0 -2
  119. data/test/filters/test_relativize_paths.rb +77 -24
  120. data/test/filters/test_rubypants.rb +0 -2
  121. data/test/filters/test_sass.rb +136 -10
  122. data/test/filters/test_slim.rb +0 -2
  123. data/test/filters/test_typogruby.rb +0 -2
  124. data/test/filters/test_uglify_js.rb +30 -0
  125. data/test/gem_loader.rb +11 -0
  126. data/test/helper.rb +3 -0
  127. data/test/helpers/test_blogging.rb +0 -2
  128. data/test/helpers/test_breadcrumbs.rb +0 -2
  129. data/test/helpers/test_capturing.rb +0 -2
  130. data/test/helpers/test_filtering.rb +0 -2
  131. data/test/helpers/test_html_escape.rb +0 -2
  132. data/test/helpers/test_link_to.rb +0 -2
  133. data/test/helpers/test_rendering.rb +0 -2
  134. data/test/helpers/test_tagging.rb +0 -2
  135. data/test/helpers/test_text.rb +0 -2
  136. data/test/helpers/test_xml_sitemap.rb +0 -2
  137. data/test/tasks/test_clean.rb +0 -2
  138. metadata +11 -9
  139. data/lib/nanoc3/cli/commands.rb +0 -16
  140. data/lib/nanoc3/cli/commands/help.rb +0 -71
  141. data/tasks/clean.rake +0 -11
@@ -1,48 +1,34 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::CLI::Commands
4
-
5
- class Debug < Cri::Command
6
-
7
- def name
8
- 'debug'
9
- end
10
-
11
- def aliases
12
- []
13
- end
14
-
15
- def short_desc
16
- 'show debug information for this site'
17
- end
18
-
19
- def long_desc
20
- 'Show information about all items, item representations and layouts ' \
21
- 'in the current site.'
22
- end
3
+ usage 'debug'
4
+ summary 'show debug information for this site'
5
+ description <<-EOS
6
+ Show information about all items, item representations and layouts in the
7
+ current site.
8
+ EOS
9
+
10
+ run do |opts, args, cmd|
11
+ Nanoc3::CLI::Commands::Debug.call(opts, args, cmd)
12
+ end
23
13
 
24
- def usage
25
- "nanoc3 debug"
26
- end
14
+ module Nanoc3::CLI::Commands
27
15
 
28
- def option_definitions
29
- []
30
- end
16
+ class Debug < ::Nanoc3::CLI::Command
31
17
 
32
- def run(options, arguments)
18
+ def run
33
19
  # Make sure we are in a nanoc site directory
34
20
  print "Loading site data... "
35
- @base.require_site
21
+ self.require_site
36
22
  puts "done"
37
23
  puts
38
24
 
39
25
  # Get data
40
- items = @base.site.items
26
+ items = self.site.items
41
27
  reps = items.map { |i| i.reps }.flatten
42
- layouts = @base.site.layouts
28
+ layouts = self.site.layouts
43
29
 
44
30
  # Get dependency tracker
45
- compiler = @base.site.compiler
31
+ compiler = self.site.compiler
46
32
  compiler.load
47
33
  dependency_tracker = compiler.dependency_tracker
48
34
 
@@ -1,36 +1,21 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::CLI::Commands
4
-
5
- class Info < Cri::Command
6
-
7
- def name
8
- 'info'
9
- end
10
-
11
- def aliases
12
- []
13
- end
14
-
15
- def short_desc
16
- 'show info about available plugins'
17
- end
18
-
19
- def long_desc
20
- 'Show a list of available plugins, including filters, data sources ' +
21
- 'and VCSes. If the current directory contains a nanoc web site, ' +
22
- 'the plugins defined in this site will be shown as well.'
23
- end
3
+ summary 'show info about available plugins'
4
+ usage 'info [options]'
5
+ description <<-EOS
6
+ Show a list of available plugins, including filters, data sources and VCSes.
7
+ If the current directory contains a nanoc web site, the plugins defined in this site will be shown as well.
8
+ EOS
9
+
10
+ run do |opts, args, cmd|
11
+ Nanoc3::CLI::Commands::Info.call(opts, args, cmd)
12
+ end
24
13
 
25
- def usage
26
- "nanoc3 info [options]"
27
- end
14
+ module Nanoc3::CLI::Commands
28
15
 
29
- def option_definitions
30
- []
31
- end
16
+ class Info < ::Nanoc3::CLI::Command
32
17
 
33
- def run(options, arguments)
18
+ def run
34
19
  # Check arguments
35
20
  if arguments.size != 0
36
21
  $stderr.puts "usage: #{usage}"
@@ -39,7 +24,7 @@ module Nanoc3::CLI::Commands
39
24
 
40
25
  # Get list of plugins (before and after)
41
26
  plugins_before = Nanoc3::Plugin.all
42
- @base.site.code_snippets if @base.site
27
+ self.site.code_snippets if self.site
43
28
  plugins_after = Nanoc3::Plugin.all
44
29
 
45
30
  # Divide list of plugins into builtin and custom
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ usage 'nanoc command [options] [arguments]'
4
+ summary 'nanoc, a static site compiler written in Ruby'
5
+
6
+ opt :l, :color, 'enable color' do
7
+ Nanoc3::CLI::Logger.instance.color = true
8
+ end
9
+
10
+ opt :d, :debug, 'enable debugging' do
11
+ Nanoc3::CLI.debug = true
12
+ end
13
+
14
+ opt :h, :help, 'show the help message and quit' do |value, cmd|
15
+ puts cmd.help
16
+ exit 0
17
+ end
18
+
19
+ opt :C, :'no-color', 'disable color' do
20
+ Nanoc3::CLI::Logger.instance.color = false
21
+ end
22
+
23
+ opt :V, :verbose, 'make nanoc output more detailed' do
24
+ Nanoc3::CLI::Logger.instance.level = :low
25
+ end
26
+
27
+ opt :v, :version, 'show version information and quit' do
28
+ gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"
29
+ engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
30
+ puts "nanoc #{Nanoc3::VERSION} (c) 2007-2011 Denis Defreyne."
31
+ puts "Running #{engine} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM} #{gem_info}"
32
+ exit 0
33
+ end
34
+
35
+ opt :w, :warn, 'enable warnings' do
36
+ $-w = true
37
+ end
@@ -1,52 +1,29 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::CLI::Commands
4
-
5
- class Update < Cri::Command
6
-
7
- def name
8
- 'update'
9
- end
3
+ usage 'update [options]'
4
+ summary 'update the data stored by the data source to a newer version'
5
+ description <<-EOS
6
+ Update the data stored by the data source to a newer format. The format in
7
+ which data is stored can change between releases, and even though backward
8
+ compatibility is usually preserved, it is often a good idea to store the site
9
+ data in a newer format so newer features can be taken advantage of.
10
10
 
11
- def aliases
12
- []
13
- end
11
+ This command will change data, and it is therefore recommended to make a
12
+ backup in case something goes wrong.
13
+ EOS
14
14
 
15
- def short_desc
16
- 'update the data stored by the data source to a newer version'
17
- end
15
+ option :c, :vcs, 'select the VCS to use'
16
+ flag :y, :yes, 'update the data without warning'
18
17
 
19
- def long_desc
20
- 'Update the data stored by the data source to a newer format. The ' +
21
- 'format in which data is stored can change between releases, and ' +
22
- 'even though backward compatibility is usually preserved, it is ' +
23
- 'often a good idea to store the site data in a newer format so newer ' +
24
- 'features can be taken advantage of.' +
25
- "\n" +
26
- 'This command will change data, and it is therefore recommended to ' +
27
- 'make a backup in case something goes wrong.'
28
- end
18
+ run do |opts, args, cmd|
19
+ Nanoc3::CLI::Commands::Update.call(opts, args, cmd)
20
+ end
29
21
 
30
- def usage
31
- "nanoc3 update [options]"
32
- end
22
+ module Nanoc3::CLI::Commands
33
23
 
34
- def option_definitions
35
- [
36
- # --vcs
37
- {
38
- :long => 'vcs', :short => 'c', :argument => :required,
39
- :desc => 'select the VCS to use'
40
- },
41
- # --yes
42
- {
43
- :long => 'yes', :short => 'y', :argument => :forbidden,
44
- :desc => 'updates the data without warning'
45
- }
46
- ]
47
- end
24
+ class Update < ::Nanoc3::CLI::Command
48
25
 
49
- def run(options, arguments)
26
+ def run
50
27
  # Check arguments
51
28
  if arguments.size != 0
52
29
  $stderr.puts "usage: #{usage}"
@@ -54,10 +31,10 @@ module Nanoc3::CLI::Commands
54
31
  end
55
32
 
56
33
  # Make sure we are in a nanoc site directory
57
- @base.require_site
34
+ self.require_site
58
35
 
59
36
  # Set VCS if possible
60
- @base.set_vcs(options[:vcs])
37
+ self.set_vcs(options[:vcs])
61
38
 
62
39
  # Check for -y switch
63
40
  unless options.has_key?(:yes)
@@ -85,7 +62,7 @@ module Nanoc3::CLI::Commands
85
62
  end
86
63
 
87
64
  # Update
88
- @base.site.data_sources.each do |data_source|
65
+ self.site.data_sources.each do |data_source|
89
66
  data_source.update
90
67
  end
91
68
  end
@@ -1,55 +1,29 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::CLI::Commands
4
-
5
- class View < Cri::Command
6
-
7
- def name
8
- 'view'
9
- end
10
-
11
- def aliases
12
- []
13
- end
14
-
15
- def short_desc
16
- 'start the web server that serves static files'
17
- end
18
-
19
- def long_desc
20
- 'Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running the autocompiler requires \'adsf\' and \'rack\'.'
21
- end
3
+ usage 'view [options]'
4
+ summary 'start the web server that serves static files'
5
+ description <<-EOS
6
+ Start the static web server. Unless specified, the web server will run on port 3000 and listen on all IP addresses. Running the autocompiler requires 'adsf' and 'rack'.
7
+ EOS
8
+
9
+ option :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
10
+ option :o, :host, 'specify the host to listen on (default: 0.0.0.0)'
11
+ option :p, :port, 'specify the port to listen on (default: 3000)'
12
+
13
+ run do |opts, args, cmd|
14
+ Nanoc3::CLI::Commands::View.call(opts, args, cmd)
15
+ end
22
16
 
23
- def usage
24
- "nanoc3 view [options]"
25
- end
17
+ module Nanoc3::CLI::Commands
26
18
 
27
- def option_definitions
28
- [
29
- # --handler
30
- {
31
- :long => 'handler', :short => 'H', :argument => :required,
32
- :desc => 'specify the handler to use (webrick/mongrel/...)'
33
- },
34
- # --host
35
- {
36
- :long => 'host', :short => 'o', :argument => :required,
37
- :desc => 'specify the host to listen on (default: 0.0.0.0)'
38
- },
39
- # --port
40
- {
41
- :long => 'port', :short => 'p', :argument => :required,
42
- :desc => 'specify the port to listen on (default: 3000)'
43
- }
44
- ]
45
- end
19
+ class View < ::Nanoc3::CLI::Command
46
20
 
47
- def run(options, arguments)
21
+ def run
48
22
  require 'rack'
49
23
  require 'adsf'
50
24
 
51
25
  # Make sure we are in a nanoc site directory
52
- @base.require_site
26
+ self.require_site
53
27
 
54
28
  # Set options
55
29
  options_for_rack = {
@@ -67,7 +41,7 @@ module Nanoc3::CLI::Commands
67
41
  end
68
42
 
69
43
  # Build app
70
- site = @base.site
44
+ site = self.site
71
45
  app = Rack::Builder.new do
72
46
  use Rack::CommonLogger
73
47
  use Rack::ShowExceptions
@@ -1,36 +1,20 @@
1
1
  # encoding: utf-8
2
2
 
3
- module Nanoc3::CLI::Commands
4
-
5
- # @since 3.2.0
6
- class Watch < Cri::Command
7
-
8
- def name
9
- 'watch'
10
- end
11
-
12
- def aliases
13
- [ ]
14
- end
15
-
16
- def short_desc
17
- 'start the watcher'
18
- end
19
-
20
- def long_desc
21
- 'Start the watcher. When a change is detected, the site will be ' \
22
- 'recompiled.'
23
- end
3
+ usage 'watch [options]'
4
+ summary 'start the watcher'
5
+ description <<-EOS
6
+ Start the watcher. When a change is detected, the site will be recompiled.
7
+ EOS
8
+
9
+ run do |opts, args, cmd|
10
+ Nanoc3::CLI::Commands::Watch.call(opts, args, cmd)
11
+ end
24
12
 
25
- def usage
26
- "nanoc3 watch"
27
- end
13
+ module Nanoc3::CLI::Commands
28
14
 
29
- def option_definitions
30
- []
31
- end
15
+ class Watch < ::Nanoc3::CLI::Command
32
16
 
33
- def run(options, arguments)
17
+ def run
34
18
  require 'fssm'
35
19
  require 'pathname'
36
20
 
@@ -78,7 +62,7 @@ module Nanoc3::CLI::Commands
78
62
  end
79
63
 
80
64
  puts
81
- @base.print_error(e)
65
+ base.print_error(e)
82
66
  puts
83
67
  end
84
68
  end
@@ -87,9 +71,10 @@ module Nanoc3::CLI::Commands
87
71
  rebuilder.call(nil, nil)
88
72
 
89
73
  # Get directories to watch
90
- watcher_config = @base.site.config[:watcher] || {}
74
+ watcher_config = self.site.config[:watcher] || {}
91
75
  dirs_to_watch = watcher_config[:dirs_to_watch] || %w( content layouts lib )
92
- files_to_watch = watcher_config[:files_to_watch] || %w( config.yaml Rules )
76
+ files_to_watch = watcher_config[:files_to_watch] || %w( config.yaml Rules rules Rules.rb rules.rb' )
77
+ files_to_watch.delete_if { |f| !File.file?(f) }
93
78
 
94
79
  # Watch
95
80
  puts "Watching for changes…".make_compatible_with_env
@@ -263,13 +263,32 @@ module Nanoc3::DataSources
263
263
  # the default external encoding, but this can be overridden by the
264
264
  # “encoding” configuration attribute in the data source configuration.
265
265
  def read(filename)
266
- data = File.read(filename)
267
- if data.respond_to?(:encode)
268
- data.force_encoding(@config[:encoding]) if @config && @config[:encoding]
269
- data.encode('UTF-8')
270
- else
271
- data
266
+ # Read
267
+ begin
268
+ data = File.read(filename)
269
+ rescue => e
270
+ raise RuntimeError.new("Could not read #{filename}: #{e.inspect}")
272
271
  end
272
+
273
+ # Fix
274
+ if data.respond_to?(:encode!)
275
+ if @config && @config[:encoding]
276
+ original_encoding = Encoding.find(@config[:encoding])
277
+ data.force_encoding(@config[:encoding])
278
+ else
279
+ original_encoding = data.encoding
280
+ end
281
+
282
+ data.encode!('UTF-8') rescue raise_encoding_error(filename, original_encoding)
283
+ raise_encoding_error(filename, original_encoding) if !data.valid_encoding?
284
+ end
285
+
286
+ data
287
+ end
288
+
289
+ # Raises an invalid encoding error for the given filename and encoding.
290
+ def raise_encoding_error(filename, encoding)
291
+ raise RuntimeError.new("Could not read #{filename} because the file is not valid #{encoding}.")
273
292
  end
274
293
 
275
294
  end
@@ -40,8 +40,8 @@ module Nanoc3::DataSources
40
40
  # (`allow_periods_in_identifiers` set to false)
41
41
  # foo.html.erb → /foo/
42
42
  #
43
- # Note that it is possible for two different, separate files to have the
44
- # same identifier. It is recommended to avoid such situations.
43
+ # Note that each item must have an unique identifier. nanoc will display an
44
+ # error if two items with the same identifier are found.
45
45
  #
46
46
  # Some more examples:
47
47
  #
@@ -103,10 +103,10 @@ module Nanoc3::DataSources
103
103
  # Returns the identifier derived from the given filename, first stripping
104
104
  # the given directory name off the filename.
105
105
  def identifier_for_filename(filename)
106
- if filename =~ /index\.[^\/]+$/
107
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /index\.[^\/\.]+$/ : /index\.[^\/]+$/)
106
+ if filename =~ /(^|\/)index\.[^\/]+$/
107
+ regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\/?index\.[^\/\.]+$/ : /\/?index\.[^\/]+$/)
108
108
  else
109
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
109
+ regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
110
110
  end
111
111
  filename.sub(regex, '').cleaned_identifier
112
112
  end