File: processor.rb

package info (click to toggle)
ruby-client-side-validations 3.2.6%2Bgh-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 676 kB
  • sloc: javascript: 3,019; ruby: 2,959; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (3)
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
$:.unshift(File.expand_path('../../lib', __FILE__))

require 'client_side_validations/version'
require 'coffee_script'
require 'date'
require 'erb'

module ClientSideValidations
  class Processor
    def self.run
      write_file
    end

    def self.root_path
      File.expand_path('../..', __FILE__)
    end

    def self.file_name
      'rails.validations'
    end

    def self.template
      ERB.new(File.open(File.join(root_path, 'coffeescript', "#{file_name}.coffee")).read)
    end

    def self.compiled_coffeescript
      CoffeeScript.compile(template.result(binding))
    end

    def self.write_file
      file = File.new(File.join(root_path, "vendor/assets/javascripts/#{file_name}.js"), 'w')
      file << compiled_coffeescript
      file.close
    end
  end
end