1 // ================================================================================================
3 // MediaWikiページのテンプレート要素をあらわすモデルクラスソース</summary>
5 // <copyright file="MediaWikiTemplate.cs" company="honeplusのメモ帳">
6 // Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
9 // ================================================================================================
11 namespace Honememo.Wptscs.Parsers
14 using System.Collections.Generic;
16 using Honememo.Parsers;
17 using Honememo.Utilities;
20 /// MediaWikiページのテンプレート要素をあらわすモデルクラスです。
22 public class MediaWikiTemplate : MediaWikiLink
29 public static readonly new string DelimiterStart = "{{";
34 public static readonly new string DelimiterEnd = "}}";
39 public static readonly string Msgnw = "msgnw:";
55 /// 指定されたタイトルのテンプレート要素をあらわすインスタンスを生成する。
57 /// <param name="title">テンプレート名。</param>
58 public MediaWikiTemplate(string title) : base(title)
69 /// <exception cref="ArgumentNullException">記事名がnullの場合。</exception>
70 /// <exception cref="ArgumentException">記事名が空の場合。</exception>
71 /// <remarks>テンプレートに記載されていた記事名であり、名前空間の情報などは含まない可能性があるため注意。</remarks>
72 public override string Title
81 this.title = Validate.NotBlank(value);
86 /// テンプレートのソースをそのまま出力することを示す msgnw: が付加されているか?
88 public virtual bool IsMsgnw
97 public virtual bool NewLine
105 #region 実装支援用抽象メソッド実装
108 /// この要素を書式化したテンプレートテキストを返す。
110 /// <returns>テンプレートテキスト。</returns>
111 protected override string ToStringImpl()
114 StringBuilder b = new StringBuilder();
117 b.Append(MediaWikiTemplate.DelimiterStart);
119 // 先頭の : の付加(テンプレート名前空間ではなく標準名前空間となる)
125 // msgnw: (テンプレートを<nowiki>タグで挟む)の付加
128 b.Append(MediaWikiTemplate.Msgnw);
131 // 言語コード・他プロジェクトコードの付加
132 if (!string.IsNullOrEmpty(this.Interwiki))
134 b.Append(this.Interwiki);
139 if (!string.IsNullOrEmpty(this.Title))
141 b.Append(this.Title);
145 if (this.Section != null)
148 b.Append(this.Section);
158 if (this.PipeTexts != null)
160 foreach (IElement p in this.PipeTexts)
163 b.Append(p.ToString());
168 b.Append(MediaWikiTemplate.DelimiterEnd);