weskit 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ Weskit [![Build Status](https://secure.travis-ci.org/f6p/weskit.png?branch=maste
2
2
  ====================================================================================================================
3
3
 
4
4
  Weskit gem consists of tools for interaction with Wesnoth Markup Langage and Wesnoth infrastructure.
5
- For more details please check out generated documentation and source code.
5
+ For more documentation check out generated ri pages and examples directory.
6
6
 
7
7
  #### Modules
8
8
 
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'weskit'
3
+
4
+ include Weskit::WML
5
+
6
+ unit = Root.new.build do
7
+ unit do
8
+ id 123
9
+ name 'Joe'
10
+ type :spearman
11
+
12
+ weapon do
13
+ name :spear
14
+ damage 10
15
+ description 'This is the weapon spearman usually uses.', :translatable => true
16
+ end
17
+ end
18
+ end
19
+
20
+ # Beware of fact that puts unit calls unit.to_ary instead of unit.to_str
21
+ # so alwas use explicit conversion if you want string representation.
22
+ puts unit.to_s
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'weskit'
3
+
4
+ include Weskit::WML
5
+
6
+ # Compared to builder example this one uses more
7
+ # conservative approach to WML creation process.
8
+
9
+ root = Root.new
10
+
11
+ object = Element.new :object
12
+ object << Attribute.new(:name, 'orb')
13
+ object << Attribute.new(:type, 'magic item')
14
+
15
+ modificationno = Element.new :modification
16
+ modification << Attribute.new(:hp, 100)
17
+
18
+ object << modification
19
+ root << object
20
+
21
+ # Set differend formatter globally.
22
+ Formatter.default = Formatter.color
23
+
24
+ puts root.to_s
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'weskit'
3
+
4
+ include Weskit::WML
5
+
6
+ # For dealing with big messed up WML files use simple parser backend (specified as second parameter).
7
+ replay = Parser.uri 'http://replays.wesnoth.org/1.10/20121112/2p__The_Freelands_Turn_16_(5909).gz', :simple
8
+
9
+ puts replay[:mp_game_title], replay[:label], $/
10
+
11
+ first_side = replay.replay_start.side[0]
12
+ puts first_side[:user_description], first_side[:type], first_side[:faction_name], $/
13
+
14
+ second_side = replay.replay_start.side[1]
15
+ puts second_side[:user_description], second_side[:type], second_side[:faction_name], $/
@@ -1,3 +1,3 @@
1
1
  module Weskit
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weskit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kpeg
@@ -88,8 +88,10 @@ files:
88
88
  - Gemfile
89
89
  - LICENSE
90
90
  - README.markdown
91
- - README.md
92
91
  - Rakefile
92
+ - examples/builder.rb
93
+ - examples/formatter.rb
94
+ - examples/replay.rb
93
95
  - lib/weskit.rb
94
96
  - lib/weskit/mp.rb
95
97
  - lib/weskit/mp/adapter.rb
data/README.md DELETED
@@ -1,150 +0,0 @@
1
- # Weskit [![Build Status](https://secure.travis-ci.org/f6p/weskit.png?branch=master)](http://travis-ci.org/f6p/weskit)
2
-
3
- Weskit gem consists of tools for interaction with Wesnoth Markup Langage and Wesnoth infrastructure.
4
- Amog this tools Ruby classes representing WML objects and WML parser are most important as understanding
5
- them is the key to understaning any other stuff bundled. This README gives quick albeit incomplete
6
- overview of Weskit WML capabilities. For more information you have to check source code and
7
- [generated documentation](http://www.rubydoc.info/github/f6p/weskit/frames).
8
-
9
- ## Containers
10
-
11
- Elements in WML document dosn't have one parent. Instead of using arrays to store multiple WML objects
12
- create instance of Weskit::WML::Root. It will let you to call advanced features avaiable for other
13
- WML objects (like formatting, modification or searching for nodes) and it is enumerable as well.
14
-
15
- ```ruby
16
- require 'weskit'
17
- include Weskit::WML
18
-
19
- root = Root.new
20
- ```
21
-
22
- While root object can store any type of WML item there are also containers for specific item types, for
23
- example to store attributes you want to use instance of Weskit::WML::Attributes. All WML containers
24
- include Weskit::WML::Mixins::Container module and some of them are subclasses of Weskit::WML::Items.
25
-
26
- ## Altering objects
27
-
28
- While you can push instances of WML objects to elements or containers and change identifiers or values
29
- manually there is a better way of doing that. Each container has build method that comes in handy.
30
-
31
- For example:
32
-
33
- ```ruby
34
- root.build do
35
- side {
36
- id 1
37
- name 'First Side', :translatable => true
38
- unit {
39
- name :John
40
- }
41
- }
42
- end
43
- ```
44
-
45
- becomes:
46
-
47
- ```
48
- [side]
49
- id=1
50
- name=_"First Side"
51
- [unit]
52
- name=John
53
- [/unit]
54
- [/side]
55
- ```
56
-
57
- Basically Builder takes advantage of method_missing and creates attributes or elements depending of method
58
- call parameters. If there is no block suppiled new attribute is created otherwise new element is added
59
- and contents of the block are evaluated in its context. Some of the calls may interfere with existing
60
- methods of Ruby objects and to solve that issue Builder provides attribute and element methods.
61
-
62
- In such case instead of calling:
63
-
64
- ```ruby
65
- object_id 1
66
- object_id {
67
- name 'foo'
68
- }
69
- ```
70
-
71
- you can do this:
72
-
73
- ```ruby
74
- attribute(:object_id, 1)
75
- element(:object_id) {}
76
- ```
77
-
78
- id is a helper method (as it interfers with Object#id) that is equivalent to:
79
-
80
- ```ruby
81
- attribute(:id, value)
82
- ```
83
-
84
- And oh well... Let's not forget that after all builder block is
85
- Ruby code so you can use any langague construct inside it as well.
86
-
87
- ## Tree searching
88
-
89
- You can search WML elements and containers for nodes of specific type. For
90
- example lets say there is a object tree representing such WML structure:
91
-
92
- ```
93
- [a]
94
- [b]
95
- [c]
96
- name=foo
97
- [/c]
98
- [/b]
99
- [b]
100
- name=bar
101
- [c]
102
- [/c]
103
- [/b]
104
- [/a]
105
- ```
106
-
107
- To get Weskit::WML::Elements container with references to all b elements you can do this:
108
-
109
- ```ruby
110
- root.a.b
111
- ```
112
-
113
- This code takes advantage of method_missing as well and if you can't use
114
- it (because of method name conflicts) its equivalent can be used:
115
-
116
- ```ruby
117
- root.find(:a).find(:b)
118
- ```
119
-
120
- as missing calls are delegated to find method. There is also find_recursively
121
- method that lets you to find elements using object criteria specified in block.
122
-
123
- ## Representation
124
-
125
- Weskit::WML objects dosn't have any representation code coupled. Special class of objects called Formatters is
126
- used to handle their display. Most commonly you will use plain text representation (default formatter)
127
- or terminal friendly colorful version of it (color formatter). Most of WML objects provide formatter
128
- seter to replace formatter associated with them but you can as well change default formatter globally
129
- by calling Formatter.default= setter method.
130
-
131
- Whatever representation you need (JSON, XML, YAML) creating new formaters shouldn't
132
- be hard. Take look at Weskit::WML::Formatters module for further reference on that matter.
133
-
134
- ## Parser
135
-
136
- Parser provides two methods: string - for parsing strings and uri - for parsing files. uri
137
- method can load remote files as well as it transparently handles archive extraction. Parsing
138
- results in return of WML object tree with one Weskit::WML::Root as the top-most element.
139
-
140
- ## Limitations
141
-
142
- Lack of preprocessor support as WML module is supposed to work with preprocessed files
143
- (at least for now). Preprocessor directives will be consumed as comments and that can
144
- lead to unexpected behaviour at times. For example if you have macro defined its
145
- contents will be added to parent element.
146
-
147
- ## TODO
148
-
149
- Implement preprocessor directives as first class memebers
150
- that could be manipulated like any other WML node.