gollum-site 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -163,6 +163,12 @@ You can customize sanitization with three options:
163
163
 
164
164
  $ gollum-site generate --allow_elements embed,object --allow_attributes src --allow_protocols irc
165
165
 
166
+ ## Ignore File
167
+
168
+ If there is a file named `.gollumignore` in the root of the repository, the
169
+ exclusions it specifies will be used to suppress gollum-site generation
170
+ accordingly. The `.gollumignore` file uses `.gitignore` semantics.
171
+
166
172
  ## Example
167
173
 
168
174
  To see gollum-site in action, let's use it to generate a static site from a
@@ -1,4 +1,5 @@
1
1
  module Gollum
2
+
2
3
  class Site
3
4
  def self.default_layout_dir()
4
5
  ::File.join(::File.dirname(::File.expand_path(__FILE__)), "layout")
@@ -33,11 +34,7 @@ module Gollum
33
34
  items.each do |item|
34
35
  filename = ::File.basename(item.path)
35
36
  dirname = ::File.dirname(item.path)
36
- if filename =~ /^_Footer./
37
- # ignore
38
- elsif filename =~ /^_Sidebar./
39
- # ignore
40
- elsif filename =~ /^_Layout.html/
37
+ if filename =~ /^_Layout.html/
41
38
  # layout
42
39
  @layouts[item.path] = ::Liquid::Template.parse(item.data)
43
40
  elsif @wiki.page_class.valid_page_name?(filename)
@@ -56,37 +53,17 @@ module Gollum
56
53
 
57
54
  def ls(version = 'master')
58
55
  if version == :working
59
- ls_opts = {
60
- :others => true,
61
- :exclude_standard => true,
62
- :cached => true,
63
- :z => true
64
- }
65
-
66
- ls_opts_del = {
67
- :deleted => true,
68
- :exclude_standard => true,
69
- :z => true
70
- }
71
-
72
- # if output_path is in work_tree, it should be excluded
73
- if ::File.expand_path(@output_path).match(::File.expand_path(@wiki.repo.git.work_tree))
74
- ls_opts[:exclude] = @output_path
75
- ls_opts_del[:exclude] = @output_path
76
- end
77
-
78
- cwd = Dir.pwd # need to change directories for git ls-files -o
79
- Dir.chdir(@wiki.repo.git.work_tree)
80
- deleted = @wiki.repo.git.native(:ls_files, ls_opts_del).split("\0")
81
- working = @wiki.repo.git.native(:ls_files, ls_opts).split("\0")
82
- work_tree = (working - deleted).map do |path|
83
- path = decode_git_path(path)
84
- OpenStruct.new(:path => path, :data => IO.read(path))
56
+ return in_work_tree do
57
+ working = ls_files(:exclude => @output_path, :others => true, :cached => true)
58
+ deleted = ls_files(:exclude => @output_path, :deleted => true)
59
+ ignored = ignored_list(version)
60
+ valid_files = working - deleted - ignored
61
+ valid_files.map do |path|
62
+ OpenStruct.new(:path => path, :data => IO.read(path))
63
+ end
85
64
  end
86
- Dir.chdir(cwd) # change back to original directory
87
- return work_tree
88
65
  else
89
- return @wiki.tree_map_for(version).map do |entry|
66
+ return @wiki.tree_map_for(version).reject {|entry| ignored? entry.path }.map do |entry|
90
67
  OpenStruct.new(:path => entry.path, :data => entry.blob(@wiki.repo).data)
91
68
  end
92
69
  end
@@ -137,5 +114,40 @@ module Gollum
137
114
  path.gsub!(/\\[rn"\\]/) { |m| eval(%("#{m.to_s}")) }
138
115
  path
139
116
  end
140
- end
141
- end
117
+
118
+ def ignored?(path)
119
+ @ignored_list ||= ignored_list
120
+ @ignored_list.include? path
121
+ end
122
+
123
+ def ignored_list(version = 'master')
124
+ in_work_tree do
125
+ ignore = ls_files(:ignored => true, :exclude_from => '.gollumignore')
126
+ if version == :working
127
+ ignore += ls_files(:ignored => true, :exclude_from => '.gollumignore', :other => true)
128
+ else
129
+ ignore += ls_files(:other => true)
130
+ end
131
+ # grit does not correctly handle multiple options with the same name
132
+ ignore += ls_files(:ignored => true, :exclude => '.gollumignore')
133
+ ignore += ls_files(:ignored => true, :exclude => '.gitignore')
134
+ ignore += ls_files(:ignored => true, :exclude => '_Sidebar.*')
135
+ ignore += ls_files(:ignored => true, :exclude => '_Footer.*')
136
+ end
137
+ end
138
+
139
+ def ls_files(opts)
140
+ opts.merge!(:z => true, :exclude_standard => true)
141
+ @wiki.repo.git.native(:ls_files, opts).split("\0").map {|path| decode_git_path(path) }
142
+ end
143
+
144
+ def in_work_tree
145
+ cwd = Dir.pwd
146
+ Dir.chdir(@wiki.repo.git.work_tree)
147
+ result = yield
148
+ Dir.chdir(cwd)
149
+ result
150
+ end
151
+ end # Site
152
+
153
+ end # Gollum
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  class Site
3
- VERSION = "0.1.10"
3
+ VERSION = "0.1.11"
4
4
  end
5
5
  end
data/test/test_site.rb CHANGED
@@ -91,6 +91,37 @@ context "Preview" do
91
91
  end
92
92
  end
93
93
 
94
+ context "Ignorefile" do
95
+ setup do
96
+ @path = testpath("examples/test_ignorefile.git")
97
+ @repo = Grit::Repo.init(@path)
98
+ File.open(@path + '/.gollumignore', 'w') { |f| f.write("Ignore*.*") }
99
+ File.open(@path + '/Home.md', 'w') { |f| f.write("Home file.") }
100
+ File.open(@path + '/IgnoreRepo.md', 'w') { |f| f.write("Ignore this repo file.") }
101
+ @repo.add(@path)
102
+ @repo.commit_all("Initial commit.")
103
+ # Add untracked working files
104
+ File.open(@path + '/IgnoreWorking.md', 'w') { |f| f.write("Ignore this working file.") }
105
+ File.open(@path + '/UseWorking.md', 'w') { |f| f.write("Use me.") }
106
+ @site = Gollum::Site.new(@path, {
107
+ :output_path => testpath("examples/site"),
108
+ :version => :working
109
+ })
110
+ @site.generate()
111
+ end
112
+
113
+ test "working site has no ignored files" do
114
+ diff = Dir[@site.output_path + "/**/*"].
115
+ map { |f| f.sub(@site.output_path, "") }
116
+ assert_equal(["/Home.html", "/UseWorking.html"], diff)
117
+ end
118
+
119
+ teardown do
120
+ FileUtils.rm_r(@site.output_path)
121
+ FileUtils.rm_r(@path)
122
+ end
123
+ end
124
+
94
125
  context "Sanitization" do
95
126
  setup do
96
127
  @path = Dir.mktmpdir('gollumsite')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gollum-site
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.10
5
+ version: 0.1.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Reverri
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-20 00:00:00 Z
13
+ date: 2011-12-10 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gollum
@@ -604,7 +604,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
604
604
  requirements: []
605
605
 
606
606
  rubyforge_project: gollum-site
607
- rubygems_version: 1.7.2
607
+ rubygems_version: 1.8.8
608
608
  signing_key:
609
609
  specification_version: 3
610
610
  summary: Static site generator for Gollum Wikis