Class: Wadling::LexiconTranslator
- Inherits:
-
Object
- Object
- Wadling::LexiconTranslator
- Defined in:
- lib/wadling.rb
Instance Attribute Summary collapse
-
#style_sheet ⇒ Object
Returns the value of attribute style_sheet.
Instance Method Summary collapse
- #footer ⇒ Object
- #header ⇒ Object
-
#initialize(style_sheet = "/public/wadl") ⇒ LexiconTranslator
constructor
A new instance of LexiconTranslator.
- #resources_base ⇒ Object
- #resources_close ⇒ Object
- #translate_resources_into_wadl(resources, prefix = '') ⇒ Object
- #translate_resources_into_wadl_files(resources, path, prefix = '') ⇒ Object
Constructor Details
#initialize(style_sheet = "/public/wadl") ⇒ LexiconTranslator
Returns a new instance of LexiconTranslator.
10 11 12 |
# File 'lib/wadling.rb', line 10 def initialize(style_sheet = "/public/wadl") @style_sheet = style_sheet end |
Instance Attribute Details
#style_sheet ⇒ Object
Returns the value of attribute style_sheet.
8 9 10 |
# File 'lib/wadling.rb', line 8 def style_sheet @style_sheet end |
Instance Method Details
#footer ⇒ Object
48 49 50 |
# File 'lib/wadling.rb', line 48 def "</wadl:application>" end |
#header ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/wadling.rb', line 32 def header "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ "<?xml-stylesheet type=\"text/xsl\" href=\"#{@style_sheet}\"?>" \ "<wadl:application xmlns:wadl=\"http://wadl.dev.java.net/2009/02\"" \ " xmlns:jr=\"http://jasperreports.sourceforge.net/xsd/jasperreport.xsd\"" \ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://wadl.dev.java.net/2009/02 wadl.xsd \">" end |
#resources_base ⇒ Object
40 41 42 |
# File 'lib/wadling.rb', line 40 def resources_base "<wadl:resources base=\"/\">" end |
#resources_close ⇒ Object
44 45 46 |
# File 'lib/wadling.rb', line 44 def resources_close "</wadl:resources>" end |
#translate_resources_into_wadl(resources, prefix = '') ⇒ Object
26 27 28 29 30 |
# File 'lib/wadling.rb', line 26 def translate_resources_into_wadl(resources, prefix = '') return empty_wadl if no_resources?(resources) raise ArgumentError.new("A resource dictionary is expected") if resources_invalid?(resources) header + resources_base + translate_resources(resources, prefix) + resources_close + end |
#translate_resources_into_wadl_files(resources, path, prefix = '') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wadling.rb', line 14 def translate_resources_into_wadl_files(resources, path, prefix = '') return empty_wadl if no_resources?(resources) raise ArgumentError.new("A resource dictionary is expected") if resources_invalid?(resources) raise ArgumentError.new("path invalid") if path_invalid?(path) resources.each do |r, v| File.open("#{path}/#{apply_prefix(v['id'], prefix)}.wadl", 'w') { |file| file.write(header + resources_base + translate_and_append_resource('', r, v, prefix) + resources_close + ) } end end |