File: embedded.vala

package info (click to toggle)
vala 0.56.18-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 57,520 kB
  • sloc: ansic: 581,293; sh: 5,357; makefile: 3,980; xml: 3,161; yacc: 1,219; lex: 374; javascript: 23
file content (123 lines) | stat: -rw-r--r-- 3,330 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* embedded.vala
 *
 * Copyright (C) 2008-2009 Didier Villevalois
 * Copyright (C) 2008-2012 Florian Brosch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Didier 'Ptitjes Villevalois <ptitjes@free.fr>
 */


public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes {
	public string url {
		get;
		set;
	}

	public string? caption {
		get;
		set;
	}

	public HorizontalAlign horizontal_align {
		get;
		set;
	}

	public VerticalAlign vertical_align {
		get;
		set;
	}

	public string? style {
		get;
		set;
	}

	public Api.Package package;

	private ResourceLocator _locator;

	internal Embedded () {
		base ();
	}

	public override void configure (Settings settings, ResourceLocator locator) {
		_locator = locator;
	}

	public override void check (Api.Tree api_root, Api.Node container, string file_path,
								ErrorReporter reporter, Settings settings)
	{
		// search relative to our file
		if (!Path.is_absolute (url)) {
			string relative_to_file = Path.build_path (Path.DIR_SEPARATOR_S,
													   Path.get_dirname (file_path),
													   url);
			if (FileUtils.test (relative_to_file, FileTest.EXISTS | FileTest.IS_REGULAR)) {
				url = (owned) relative_to_file;
				package = container.package;
				return ;
			}
		}

		// search relative to the current directory / absolute path
		if (!FileUtils.test (url, FileTest.EXISTS | FileTest.IS_REGULAR)) {
			string base_name = Path.get_basename (url);

			foreach (unowned string dir in settings.alternative_resource_dirs) {
				string alternative_path = Path.build_path (Path.DIR_SEPARATOR_S,
														 dir,
														 base_name);
				if (FileUtils.test (alternative_path, FileTest.EXISTS | FileTest.IS_REGULAR)) {
					url = (owned) alternative_path;
					package = container.package;
					return ;
				}
			}

			string node_segment = (container is Api.Package)? "" : container.get_full_name () + ": ";
			reporter.simple_error ("%s: %s{{".printf (file_path, node_segment),
								   "'%s' does not exist", url);
		} else {
			package = container.package;
		}
	}

	public override void accept (ContentVisitor visitor) {
		visitor.visit_embedded (this);
	}

	public override bool is_empty () {
		return false;
	}

	public override ContentElement copy (ContentElement? new_parent = null) {
		Embedded embedded = new Embedded ();
		embedded.parent = new_parent;

		embedded.horizontal_align = horizontal_align;
		embedded.vertical_align = vertical_align;
		embedded._locator = _locator;
		embedded.caption = caption;
		embedded.package = package;
		embedded.style = style;
		embedded.url = url;

		return embedded;
	}
}