コード例 #1
0
		/////////////////////////////////////////////////////////////////////////////

		#region code
		//
		// template is in Templates.cs
		//
		public Tuple<string, string> Build()
		{
			// ******
			var tagList = new TagList { };
			tagList.AddChild( new QuickTag( "h4" )
					.SetValue( About ) );

			// ******
			var instance = Templates.MoneyFlowTemplate.CreateTemplateInstance();
			foreach( var item in AccountSummaryData.Create() ) {
				instance.AddBodyRow(
					item.Col1.ToString( "dd MMM yyyy" ),
					item.Col2.ToString( "n" ),
					item.Col3.ToString( "n" ),
					item.Col4.ToString( "n" ),
					item.Col5.ToString( "n" ),
					item.Col6.ToString( "n" ),
					item.Col7.ToString( "n" )
				);
			}

			// ******
			tagList.AddChild( instance.CreateTable() );
			return new Tuple<string, string>( Render( tagList ), nameof( TableWithTemplate1 ) );
		}
コード例 #2
0
		/////////////////////////////////////////////////////////////////////////////

		#region code
		public Tuple<string, string> Build()
		{
			// ******
			var tagList = new TagList { };
			tagList.AddChild( new QuickTag( "h4" )
					.SetValue( About ) );

			// ******
			var table = new Table( caption: "Money Flow", border: 0, id: "", attrAndStyles: "background : ivory" );
			tagList.AddChild( table );

			// ******
			foreach( var item in AccountSummaryData.Create() ) {
				table.AddBodyRow(
						Content( item.Col1.ToString( "dd MMM yyyy" ), "width : 100px", "text-align : right" ),
						Content( item.Col2.ToString(), "width : 100px", "text-align : right" ),
						Content( item.Col3.ToString(), "width : 100px", "text-align : right" ),
						Content( item.Col4.ToString(), "width : 100px", "text-align : right" ),
						Content( item.Col5.ToString(), "width : 100px", "text-align : right" ),
						Content( item.Col6.ToString(), "width : 100px", "text-align : right" ),
						Content( item.Col7.ToString(), "width : 100px", "text-align : right", item.Col7 < 0 ? "color : red" : "" )
				);
			}

			// ******
			return new Tuple<string, string>( Render( tagList ), nameof( TableWithFormatting2 ) );
		}
コード例 #3
0
ファイル: TableWithData.cs プロジェクト: gitsharper/SharpHtml
		/////////////////////////////////////////////////////////////////////////////

		#region code
		public Tuple<string, string> Build()
		{
			// ******
			var tagList = new TagList { };

			tagList.AddChild( new QuickTag( "h4" )
				.SetValue( About )
			);
			
			// ******
			var table = new Table( caption: "Checking Account", border: 0, id: "", attrAndStyles: "" );
			tagList.AddChild( table );

			// ******
			foreach( var item in AccountSummaryData.Create() ) {
				table.AddBodyRow(
						item.Col1.ToString( "dd MMM yyyy" ),
						item.Col2.ToString(),
						item.Col3.ToString(),
						item.Col4.ToString(),
						item.Col5.ToString(),
						item.Col6.ToString(),
						item.Col7.ToString()
				);
			}

			// ******
			return new Tuple<string, string>( Render( tagList ), nameof( TableWithData ) );
		}
コード例 #4
0
		/////////////////////////////////////////////////////////////////////////////

		#region code
		public Tuple<string, string> Build()
		{
			// ******
			var tagList = new TagList { };
			tagList.AddChild( new QuickTag( "h4" )
					.SetValue( About ) );

			// ******
			var table = new Table();
			tagList.AddChild( table );

			table.AddAttributesAndStyles(
				"table-layout: fixed",
				"border-collapse: collapse",
				"border: 1px solid black",
				"margin: 0px",
				"padding : 0",
				"background : ivory"
				);

			table.AddHeaderRow( Content( "", "colspan = 4" ), Content( $"4 month moving average", "colspan = 3" ) )
				.AddHeaderRow( "Ending Date", "In", "Out", "Diff", "Moving Avg In", "Moving Avg Out", "Moving Avg Diff" );

			table.AddStyleBlock( StyleBlockAddAs.Class, "td, th", "border : 1px solid black" );

			table.AddBodyStyles();

			//
			// yet another way to set body styles; a StylesFunc allows the interception of columns as they are
			// added, parameters are the column number being added and the StylesDictionary that represents that
			// column, return an IEnumerable<string> of styles to merge, or manipulate the styles dictionary
			// itself
			//
			// breaking out the StyleFunction on it's own makes this look a lot less messy and more readable than
			// inserting the lambda directly into SetDefaultBodyStyles() - at least for the sake of an example
			//
			StylesFunc sf = ( col, sd ) => col > 3 ? Styles( "font-style : italic " ) : null;
			table.SetDefaultBodyStyles( sf, 7, "width : 100px", "text-align : right" );

			// ******
			foreach( var item in AccountSummaryData.Create() ) {
				table.AddBodyRow(
						item.Col1.ToString( "dd MMM yyyy" ),
						item.Col2.ToString(),
						item.Col3.ToString(),
						item.Col4.ToString(),
						item.Col5.ToString(),
						item.Col6.ToString(),
						Content( item.Col7.ToString(), item.Col7 < 0 ? "color : red" : null )
				);
			}

			// ******
			return new Tuple<string, string>( Render( tagList ), nameof( TableWithFormatting3 ) );
		}
コード例 #5
0
		/////////////////////////////////////////////////////////////////////////////

		public Tuple<string, string> Build()
		{
			// ******
			var tagList = new TagList { };

			tagList.AddChild( new QuickTag( "h4" )
				.SetValue( About )
			);

			// ******
			var instance = Templates.MoneyFlowTemplate.CreateTemplateInstance();
			foreach( var item in AccountSummaryData.Create() ) {
				instance.AddBodyRow(
					//
					// we can modify cells as they are added
					//
					( row, column, tag ) => ModifyTags( item, row, column, tag ),

					item.Col1.ToString( "dd MMM yyyy" ),
					item.Col2.ToString( "n" ),
					item.Col3.ToString( "n" ),

					//
					// we don't have to monitor each tag as it's created, we can 
					// modify the tag "inline" by passing a CellFunc as a callback,
					// note: we do have to add the data ourself
					//
					(CellFunc) (( row, col, tag ) => {
						tag.SetValue( item.Col4.ToString( "n" ) );
						if( item.Col4 < 0 ) {
							tag.AddStyles( "color : red" );
						}
						return null;
					}),

					item.Col5.ToString( "n" ),
					item.Col6.ToString( "n" ),

					//
					// yet another way to customize the adding of data, if we pass an IEnumerable<string>
					// the first string will be used for the content of the tag and the remaining
					// items are parsed as attributes and styles ("style : value", "attribute = value")
					//
					Content( item.Col7.ToString( "n" ), item.Col7 < 0 ? "color : red" : "" )
				);
			}

			// ******
			tagList.AddChild( instance.CreateTable() );
			return new Tuple<string, string>( Render( tagList ), nameof( TableWithTemplate2 ) );
		}
コード例 #6
0
ファイル: Program.cs プロジェクト: gitsharper/SharpHtml
		/////////////////////////////////////////////////////////////////////////////

		static void RunTableExamples1( IEnumerable<string> items )
		{
			// ******
			int index = 0;
			string directory = string.Empty;
			var tagList = new TagList { };

			// ******
			foreach( var example in TableExamples() ) {
				var htmlPath = example.Item1;
				var about = example.Item2;

				if( 0 == index ) {
					directory = Path.GetDirectoryName( htmlPath );
				}

				tagList.AddChild( new A( "file:///" + htmlPath ).SetValue( about ) );
			}

			//var div = new Div().AppendChildren( tagList );

			var list = new Ul().AddListItems( tagList );

			// ******
			//var page = new SimplePage<SimpleHtml> { };
			//page.AddBodyContent( tagList );
			//var html = page.Html.Render();

			var html = new BasicHtml( "Index" );
			html.BodyContainer.AddChild( list );
			var text = html.Render();

			File.WriteAllText( Path.Combine( directory,"index.html" ), text );
		}