public
Description: A small Rails-inspired library of PHP helper functions. Simple stuff that really should be in core PHP.
Homepage:
Clone URL: git://github.com/jaz303/php-helpers.git
php-helpers / Rakefile
100644 42 lines (35 sloc) 0.972 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
PHP = ENV['PHP'] || "/usr/local/bin/php"
SOURCES = %w(preamble primitive support array_path query_string asset tag form)
SOURCES_5_3 = %w(functional)
 
OUTPUT = {
  'helpers.php' => SOURCES,
  'helpers-5.3.php' => SOURCES + SOURCES_5_3
}
 
def synthesize(php_file, sources)
  file php_file => sources.map { |s| "src/#{s}.php"} do
    File.open(php_file, 'w') do |out|
      out.write("<?php\n")
      sources.each do |src|
        in_php = false
        File.open('src/' + src + '.php').each do |line|
          if line =~ /^<\?php/
            in_php = true
          elsif line =~ /^\?>/
            in_php = false
          elsif in_php
            out.write(line)
          end
        end
      end
      out.write("?>\n")
    end
  end
end
 
OUTPUT.each { |php_file, sources| synthesize(php_file, sources) }
 
task :build => OUTPUT.keys
 
task :clean do
  OUTPUT.keys.each { |k| FileUtils.rm_f(k) }
end
 
task :test => 'helpers-5.3.php' do
  sh "#{PHP} run_tests.php"
end