libeagle 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ module LibEagle
2
+ class ElementClassNotFound < StandardError; end
3
+ class Parser
4
+
5
+ def self.initElementClass(name,xml)
6
+ class_name = LibEagle::CLASS_NAMES[name]
7
+ if class_name
8
+ LibEagle::const_get(class_name).new_with_xml(xml)
9
+ else
10
+ raise ElementClassNotFound.new("Element: `#{name}` class wasn't found in the list of the known classes")
11
+ end
12
+ end
13
+
14
+ def self.parseFile(file)
15
+ content = IO.read(file)
16
+ parseXML(content)
17
+ end
18
+
19
+ def self.parseXML(xml_content)
20
+ xml = Nokogiri::XML(xml_content)
21
+ root = xml.root
22
+ eagle = initElementClass(root.name, root)
23
+ return eagle
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,83 @@
1
+ module LibEagle
2
+ module Types
3
+ def Types.Bool
4
+ /^(no|yes)$/i
5
+ end
6
+
7
+ def Types.GridUnit
8
+ /^(mic|mm|mil|inch)$/i
9
+ end
10
+
11
+ def Types.GridStyle
12
+ /^(lines|dots)$/i
13
+ end
14
+
15
+ def Types.WireStyle
16
+ /^(continuous|longdash|shortdash|dashdot)$/i
17
+ end
18
+
19
+ def Types.WireCap
20
+ /^(flat|round)$/i
21
+ end
22
+
23
+ def Types.PadShape
24
+ /^(square|round|octagon|long|offset)$/i
25
+ end
26
+
27
+ def Types.ViaShape
28
+ /^(square|round|octagon)$/i
29
+ end
30
+
31
+ def Types.TextFont
32
+ /^(vector|proportional|fixed)$/i
33
+ end
34
+
35
+ def Types.AttributeDisplay
36
+ /^(off|value|name|both)$/i
37
+ end
38
+
39
+ def Types.PolygonPour
40
+ /^(solid|hatch|cutout)$/i
41
+ end
42
+
43
+ def Types.PinVisible
44
+ /^(off|pad|pin|both)$/i
45
+ end
46
+
47
+ def Types.PinLength
48
+ /^(point|short|middle|long)$/i
49
+ end
50
+
51
+ def Types.PinDirection
52
+ /^(nc|in|out|io|oc|pwr|pas|hiz|sup)$/i
53
+ end
54
+
55
+ def Types.PinFunction
56
+ /^(none|dot|clk|dotclk)$/i
57
+ end
58
+
59
+ def Types.GateAddLevel
60
+ /^(must|can|next|request|always)$/i
61
+ end
62
+
63
+ def Types.ContactRoute
64
+ /^(all|any)$/i
65
+ end
66
+
67
+ def Types.DimensionType
68
+ /^(parallel|horizontal|vertical|radius|diameter|leader)$/i
69
+ end
70
+
71
+ def Types.Severity
72
+ /^(info|warning|error)$/i
73
+ end
74
+
75
+ def Types.Align
76
+ /^(bottom-left|bottom-center|bottom-right|center-left|center|center-right|top-left|top-center|top-right)$/i
77
+ end
78
+
79
+ def Types.VerticalText
80
+ /^(up|down)$/i
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module Libeagle
2
+ VERSION = "1.1"
3
+ end
@@ -0,0 +1,118 @@
1
+ module LibEagle
2
+ module XML
3
+ class Loader
4
+ def parse(xml_content)
5
+ xml = Nokogiri::XML(xml_content)
6
+ return xml.root
7
+ end
8
+
9
+ def loadBlock(block)
10
+ parse(block)
11
+ end
12
+
13
+ def loadFile(file)
14
+ if File.exists?(file)
15
+ xml_content = IO.read(file)
16
+ parse(xml_content)
17
+ else
18
+ return false
19
+ end
20
+ end
21
+ end
22
+
23
+ class Saver
24
+ attr_accessor :htmlentities,
25
+ :output,
26
+ :lib_eagle_objects,
27
+ :values
28
+
29
+ XML_DECLARATION = %(<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE eagle SYSTEM "eagle.dtd">\n)
30
+
31
+ def rname(name)
32
+ name.gsub(/^clazz$/, "class")
33
+ end
34
+
35
+ def initialize(lib_eagle_objects,values)
36
+ @output = ""
37
+ @lib_eagle_objects = lib_eagle_objects
38
+ @values = values
39
+ @htmlentities = HTMLEntities.new
40
+ end
41
+
42
+ def tag_name
43
+ if @lib_eagle_objects[:element_name]
44
+ return @values.element_name
45
+ else
46
+ return @values.class.name.split("::").last.downcase
47
+ end
48
+ end
49
+
50
+ def open_tag_base(ending)
51
+ xml = "<#{tag_name}"
52
+ @lib_eagle_objects[:attributes].each_pair do|attribute, params|
53
+ attribute = rname(attribute)
54
+ if @values.instance_variable_get("@attribute_#{attribute}")
55
+ value = @values.instance_variable_get("@attribute_#{attribute}")
56
+ xml << " #{attribute}=\"#{value}\""
57
+ end
58
+ end
59
+ xml << ending
60
+ @output << xml
61
+ end
62
+
63
+ def empty_tag
64
+ open_tag_base("/>\n")
65
+ end
66
+
67
+ def open_tag
68
+ open_tag_base(">\n")
69
+ end
70
+
71
+ def open_tag_content
72
+ open_tag_base(">")
73
+ end
74
+
75
+ def close_tag
76
+ @output << "</#{tag_name}>\n"
77
+ end
78
+
79
+ def content
80
+ @output << @htmlentities.encode(@values.content)
81
+ end
82
+
83
+ def objects
84
+ xml = ""
85
+ @lib_eagle_objects[:objects].each_pair do |object, params|
86
+ object = rname(object)
87
+ objects = @values.instance_variable_get("@object_#{object}")
88
+ if objects.is_a? Array
89
+ objects.each do |obj|
90
+ xml << obj.saveXML
91
+ end
92
+ elsif objects != nil
93
+ xml << objects.saveXML
94
+ end
95
+ end
96
+ @output << xml
97
+ end
98
+
99
+ def parse
100
+ if @lib_eagle_objects[:root_element]
101
+ @output << XML_DECLARATION
102
+ end
103
+ if @lib_eagle_objects[:empty_element]
104
+ empty_tag
105
+ elsif @lib_eagle_objects[:text_content]
106
+ open_tag_content
107
+ content
108
+ close_tag
109
+ else
110
+ open_tag
111
+ objects
112
+ close_tag
113
+ end
114
+ @output
115
+ end
116
+ end
117
+ end
118
+ end
data/libeagle.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/libeagle/version', __FILE__)
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Aurimas Niekis"]
5
+ gem.email = ["aurimas.niekis@gmail.com"]
6
+ gem.description = %q{CadSoft Eagle Ruby Library}
7
+ gem.summary = %q{This gem provides functionality to manage CadSoft Eagle Files}
8
+ gem.homepage = "http://www.gcds.lt"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "libeagle"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Libeagle::VERSION
16
+ gem.add_dependency('nokogiri')
17
+ gem.add_dependency('htmlentities')
18
+ gem.licenses = ['MIT', 'GPL-2']
19
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libeagle
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aurimas Niekis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: htmlentities
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: CadSoft Eagle Ruby Library
47
+ email:
48
+ - aurimas.niekis@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - GPL_license.txt
55
+ - Gemfile
56
+ - LICENSE
57
+ - MIT_license.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/libeagle.rb
61
+ - lib/libeagle/base.rb
62
+ - lib/libeagle/eagle.rb
63
+ - lib/libeagle/libeagle.rb
64
+ - lib/libeagle/types.rb
65
+ - lib/libeagle/version.rb
66
+ - lib/libeagle/xml.rb
67
+ - libeagle.gemspec
68
+ homepage: http://www.gcds.lt
69
+ licenses:
70
+ - MIT
71
+ - GPL-2
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.24
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: This gem provides functionality to manage CadSoft Eagle Files
94
+ test_files: []