wcc 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,13 +27,13 @@ and then
27
27
 
28
28
  wcc-init
29
29
 
30
- At this time you should run the ´wcc´ command only in this directory since wcc reads it's
30
+ At this time you should run the `wcc` command only in this directory since wcc reads it's
31
31
  configuration by default from './conf.yml'.
32
32
 
33
33
  Usage
34
34
  -----
35
35
 
36
- The installed 'wcc' gem provides a ´wcc´ binary on the command line.
36
+ The installed 'wcc' gem provides a `wcc` binary on the command line.
37
37
  It can invoked by hand or automatically via *cron* on a server environment.
38
38
 
39
39
  For using wcc you need to specify some options:
@@ -71,7 +71,7 @@ Then don't forget to run
71
71
 
72
72
  in your '/my/conf' directory which interactively asks to overwrite local 'assets'
73
73
  like mail templates and filters with the original ones out of the gem (which you copied
74
- there using ´wcc-init´ at the beginning).
74
+ there using `wcc-init` at the beginning).
75
75
 
76
76
  NOTE: You should **make a backup** (especially of your **conf.yml**) of the '/my/conf'
77
77
  directory **before upgrading**.
data/assets/conf.yml CHANGED
@@ -25,6 +25,8 @@ sites:
25
25
  - test
26
26
  - arg-test: {number: 5, hello: world}
27
27
  - only_changes_of: {at_least: 4, t: lines}
28
+ # Regex filter that performs matching against <scope> (one of full or diff)
29
+ - matches: {regex: '(normal|regex)[!]+', flags: i, scope: diff}
28
30
  # readable, isn't it?
29
31
  - url: https://my.secret.place/
30
32
  emails:
@@ -0,0 +1,11 @@
1
+
2
+ WCC::Filters.add 'and' do |data,args|
3
+ ret = true
4
+ args.each do |id,inner_args|
5
+ if not WCC::Filters.call(data, id, inner_args)
6
+ # short circuit
7
+ ret = false; break
8
+ end
9
+ end
10
+ ret
11
+ end
@@ -12,6 +12,7 @@ WCC::Filters.add 'changes_of' do |data,args|
12
12
  when 'hunk','hunks'
13
13
  cmp_val = data.diff.nhunks
14
14
  end
15
+ WCC::Filters.debug "changes_of #{cmp_val} #{args['t'] || args['type']}"
15
16
  next (cmp_val >= args['at_least']) if args.key?('at_least')
16
17
  next (cmp_val > args['more_than']) if args.key?('more_than')
17
18
  next (cmp_val <= args['at_most']) if args.key?('at_most')
@@ -0,0 +1,27 @@
1
+
2
+ WCC::Filters.add 'matches' do |data,args|
3
+ WCC::Filters.debug "regex: #{args['regex']}"
4
+ # args['flags'] is assumed to be a string that might be empty or
5
+ # contains any of the characters 'i','e','m' in any order.
6
+ ropts = []
7
+ if not args['flags'].nil?
8
+ WCC::Filters.debug "flags: #{args['flags']}"
9
+ ropts << Regexp::IGNORECASE if args['options'].include?('i')
10
+ ropts << Regexp::EXTENDED if args['options'].include?('e')
11
+ ropts << Regexp::MULTILINE if args['options'].include?('m')
12
+ end
13
+ WCC::Filters.debug "ropts: #{ropts.inspect}"
14
+ if ropts.empty?
15
+ r = Regexp.new(args['regex'])
16
+ else
17
+ r = Regexp.new(args['regex'], ropts.inject {|acc,x| acc |= x})
18
+ end
19
+ case args['scope']
20
+ when 'diff','change',nil
21
+ md = r.match(data.diff.to_s)
22
+ when 'site','full'
23
+ md = r.match(data.site.content)
24
+ end
25
+ WCC::Filters.debug "match: #{md.inspect}"
26
+ (not md.nil?)
27
+ end
@@ -0,0 +1,5 @@
1
+
2
+ WCC::Filters.add 'not' do |data,args|
3
+ id = args.keys.first
4
+ (not WCC::Filters.call(data, id, args[id]))
5
+ end
@@ -0,0 +1,11 @@
1
+
2
+ WCC::Filters.add 'or' do |data,args|
3
+ ret = false
4
+ args.each do |id,inner_args|
5
+ if WCC::Filters.call(data, id, inner_args)
6
+ # short circuit
7
+ ret = true; break
8
+ end
9
+ end
10
+ ret
11
+ end
@@ -6,11 +6,13 @@ WCC::Filters.add 'rel_changes_of' do |data,args|
6
6
  case args['percent_of']
7
7
  when 'all_lines',nil
8
8
  percent = data.diff.nlinesc.to_f / data.site.content.count("\n").+(1).to_f * 100
9
+ # TODO: extend rel_changes_of filter
9
10
  # when 'all_chars','all_characters'
10
11
  # percent = ...
11
12
  # when 'nonblank_lines'
12
13
  # percent = ...
13
14
  end
15
+ WCC::Filters.debug "rel_changes_of #{percent} of #{args['percent_of']}"
14
16
  next (percent >= args['at_least']) if args.key?('at_least')
15
17
  next (percent > args['more_than']) if args.key?('more_than')
16
18
  next (percent <= args['at_most']) if args.key?('at_most')
@@ -78,11 +78,11 @@
78
78
  <% elsif o.status == :range %>
79
79
  <li class="range">@@<%= o.text %></li>
80
80
  <% elsif o.status == :ins %>
81
- <li class="ins">+<%= o.html_hilite_text('x') %></li>
81
+ <li class="ins">+&nbsp;<%= o.html_hilite_text('x').lstrip %></li>
82
82
  <% elsif o.status == :del %>
83
- <li class="del">-<%= o.html_hilite_text('x') %></li>
83
+ <li class="del">-&nbsp;<%= o.html_hilite_text('x').lstrip %></li>
84
84
  <% else %>
85
- <li class="other"><%= o.text == ' ' ? '&nbsp;' : o.text %></li>
85
+ <li class="other">&nbsp;&nbsp;<%= o.text.substring(1).lstrip %></li>
86
86
  <% end %>
87
87
  <% end %>
88
88
  </ul>
data/lib/wcc/diff.rb CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
2
  module WCC
3
- # TODO: Handle tabs/trailing whitespace in output
4
3
 
5
4
  class DiffItem
6
5
  attr_reader :status, :text
@@ -19,10 +18,10 @@ module WCC
19
18
  @text = line.substring(2)
20
19
  elsif line.start_with?('+')
21
20
  @status = :ins
22
- @text = line.substring(1).rstrip
21
+ @text = line.substring(1)
23
22
  elsif line.start_with?('-')
24
23
  @status = :del
25
- @text = line.substring(1).rstrip
24
+ @text = line.substring(1)
26
25
  else
27
26
  @status = :other
28
27
  @text = line.rstrip
@@ -92,7 +91,7 @@ module WCC
92
91
  when :del
93
92
  '-'+text
94
93
  when :other
95
- text
94
+ ' '+text
96
95
  end
97
96
  end
98
97
  end
data/lib/wcc/filter.rb CHANGED
@@ -14,11 +14,49 @@ module WCC
14
14
  class Filters
15
15
  @@filters = {}
16
16
 
17
+ # API method - register a filters code block under given ID.
18
+ # Should be called by filters the following way:
19
+ #
20
+ # WCC::Filters.add 'filter-name' { block }
21
+ #
22
+ # @param [String] id the "name" of the filter
23
+ # @param [Proc] block a block of code returning true (Accept)
24
+ # or false (Decline) as the filters result
17
25
  def self.add(id, &block)
18
26
  WCC.logger.info "Adding filter '#{id}'"
19
27
  @@filters[id] = block
20
28
  end
21
29
 
30
+ # API method - invoke the specfied filter and give it's result.
31
+ #
32
+ # @param [Object] data arbitrary data the filter might use
33
+ # @param [String] id the "name" of the filter
34
+ # @param [Hash] args the arguments of the filter
35
+ # @return [Boolean] true if filter returned true, false otherwise
36
+ def self.call(data, id, args = {})
37
+ block = @@filters[id]
38
+ if block.nil?
39
+ raise "Call to requested filter '#{id}' failed - filter not found!"
40
+ end
41
+ block.call(data, args)
42
+ end
43
+
44
+ # API method - log msg as error
45
+ def self.error(msg); WCC.logger.error "filter: #{msg}" end
46
+ # API method - log msg as warn
47
+ def self.warn(msg); WCC.logger.warn "filter: #{msg}" end
48
+ # API method - log msg as info
49
+ def self.info(msg); WCC.logger.info "filter: #{msg}" end
50
+ # API method - log msg as debug
51
+ def self.debug(msg); WCC.logger.debug "filter: #{msg}" end
52
+
53
+ # Called by wcc check routine to evaluate all filters
54
+ # and produce and'ed result of their boolean returns.
55
+ #
56
+ # @param [Object] data arbitrary data the filters might use
57
+ # @param [Array] filters list of FilterRefs with the IDs of the
58
+ # filters to be executed
59
+ # @return [Boolean] true if all filters returned true, false otherwise
22
60
  def self.accept(data, filters)
23
61
  return true if filters.nil?
24
62
 
data/lib/wcc.rb CHANGED
@@ -45,7 +45,7 @@ end
45
45
 
46
46
  module WCC
47
47
 
48
- VERSION = "1.2.0"
48
+ VERSION = "1.3.0"
49
49
 
50
50
  DIFF_TIME_FMT = '%Y-%m-%d %H:%M:%S %Z'
51
51
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 1.2.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Nicolai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-12 00:00:00 Z
18
+ date: 2011-10-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: htmlentities
@@ -58,8 +58,12 @@ extra_rdoc_files:
58
58
  - README.md
59
59
  files:
60
60
  - assets/conf.yml
61
+ - assets/filter.d/and.rb
61
62
  - assets/filter.d/arg-test.rb
62
63
  - assets/filter.d/changes_of.rb
64
+ - assets/filter.d/matches.rb
65
+ - assets/filter.d/not.rb
66
+ - assets/filter.d/or.rb
63
67
  - assets/filter.d/rel_changes_of.rb
64
68
  - assets/filter.d/test.rb
65
69
  - assets/template.d/mail.alt.erb