Top Level Namespace

Constant Summary collapse

SHAML_VERSION =
"0.3.7"
TEMPLATEDIR =
File.join(File.dirname(__FILE__),"templates")

Instance Method Summary collapse

Instance Method Details

#camelcase(phrase) ⇒ Object



17
18
19
# File 'lib/shaml.rb', line 17

def camelcase(phrase)
  phrase.gsub(/^[a-z]|[ _]+[a-z]/) { |a| a.upcase }.gsub(/[ _]/, '')
end

#convert_file(file, appname, modelname, propertydescriptor) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/shaml.rb', line 31

def convert_file(file, appname, modelname, propertydescriptor)
  out = ""
  pstring = ""
  insideprop = false
  file.each_line do |line|
    if insideprop then
      if line.strip=="__END__PROPERTY__" then
        propertydescriptor.split(";").each do |property|
          p = property.split(":")
          out << pstring.gsub("PropertyType",p[1]).gsub("Property",p[0])
        end
        insideprop = false
      else
        pstring << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
      end
    else
      if line.strip=="__BEGIN__PROPERTY__" then
        pstring = ""
        insideprop = true
      else
        out << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
      end
    end
  end
  out
end

#copy_file(from, to, appname, modelname, propertydescriptor) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/shaml.rb', line 58

def copy_file(from,to,appname,modelname,propertydescriptor)
  
  outfname = to.gsub("WebSample",camelcase(modelname))
  FileUtils.mkdir_p(File.dirname(outfname))
  File.open(from,"rb") do |infile|
    File.open(outfname,"wb+") do |outfile|
      puts "Writing #{outfname}"        
      outfile.write convert_file(infile.read,appname,modelname,propertydescriptor)
    end
  end
end

#getappnameObject



8
9
10
11
12
13
14
15
# File 'lib/shaml.rb', line 8

def getappname
  appname = Dir.glob("*.sln").first
  if appname.nil? 
    puts 'S#aml ERROR: solution file not found. Change directory to a s#aml-architecture project'
    exit
  end
  appname.gsub(".sln","")
end

#unzip_file(file, destination) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/shaml.rb', line 21

def unzip_file(file, destination)
  Zip::ZipFile.open(file) { |zip_file|
   zip_file.each { |f|
     f_path=File.join(destination, f.name)
     FileUtils.mkdir_p(File.dirname(f_path))
     zip_file.extract(f, f_path) unless File.exist?(f_path)
   }
  }
end