Class: VisualStudioFiles::CsProj
- Inherits:
-
Object
- Object
- VisualStudioFiles::CsProj
- Defined in:
- lib/visual_studio_files.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
- #add(ref) ⇒ Object
- #clear_links ⇒ Object
- #element_types ⇒ Object
- #files ⇒ Object
-
#initialize(content) ⇒ CsProj
constructor
A new instance of CsProj.
- #to_s ⇒ Object
- #write(output) ⇒ Object
Constructor Details
#initialize(content) ⇒ CsProj
Returns a new instance of CsProj.
7 8 9 10 11 |
# File 'lib/visual_studio_files.rb', line 7 def initialize(content) @content = content @xmldoc = REXML::Document.new(@content) @xmlns = {"x"=>"http://schemas.microsoft.com/developer/msbuild/2003"}; end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/visual_studio_files.rb', line 6 def content @content end |
Instance Method Details
#add(ref) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/visual_studio_files.rb', line 36 def add(ref) ref = FileReference.new(ref) if !ref.is_a? FileReference last = REXML::XPath.match(@xmldoc,"/x:Project/x:ItemGroup/", @xmlns).last el = last.add_element(ref.type,{'Include'=>ref.file}) if ref.link el.add_element('Link').add_text(ref.link) end if ref.dependent_upon el.add_element('DependentUpon').add_text(ref.dependent_upon) end if ref.generator el.add_element('Generator').add_text(ref.generator) end if ref.sub_type el.add_element('SubType').add_text(ref.sub_type) end end |
#clear_links ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/visual_studio_files.rb', line 55 def clear_links() element_types.each { |elementType| REXML::XPath.each(@xmldoc,"/x:Project/x:ItemGroup/x:#{elementType}", @xmlns) { |file| links = file.elements.select{ |el| el.name == 'Link' } if (links.any?) file.parent.delete_element(file) end } } end |
#element_types ⇒ Object
13 14 15 |
# File 'lib/visual_studio_files.rb', line 13 def element_types ['Compile','Content','EmbeddedResource','None', 'Page'] end |
#files ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/visual_studio_files.rb', line 16 def files() files=[] element_types.each { |elementType| REXML::XPath.each(@xmldoc,"/x:Project/x:ItemGroup/x:#{elementType}", @xmlns) { |file| links = file.elements.select{ |el| el.name == 'Link' }.map { |e| e.get_text.value } depend_upon = file.elements.select { |el| el.name == 'DependentUpon' }.map { |e| e.get_text.value } generator = file.elements.select { |el| el.name == 'Generator' }.map { |e| e.get_text.value } sub_type = file.elements.select { |el| el.name == 'SubType' }.map { |e| e.get_text.value } files.push(FileReference.new({ :file=>file.attributes['Include'], :type=>elementType, :link=> links.first, :dependent_upon=>depend_upon.first, :generator => generator.first, :sub_type => sub_type.first })) } } return files end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/visual_studio_files.rb', line 65 def to_s return @xmldoc.to_s end |
#write(output) ⇒ Object
68 69 70 71 72 |
# File 'lib/visual_studio_files.rb', line 68 def write output formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true # This is the magic line that does what you need! formatter.write(@xmldoc, output) end |