RazorEngineでHTMLメールとテキストメールのテンプレートを作成する。

RazorEngineを使ったメールテンプレート作成方法。

antaris.github.io

テンプレートに埋め込むモデルを定義する。

namespace MailApp.Models.Mail
{
    public class Template
    {
        public string Name { get; set; }
    }
}

テンプレートファイルを指定して、その中身をすべて読み込む。

var templateTextPath = "~/MailTemplates/template.txt";
var templateHtmlPath = "~/MailTemplates/template.cshtml";

// テンプレート読み込み
var templateText = File.ReadAllText(HttpContext.Current.Server.MapPath(templateTextPath));
var templateHtml = File.ReadAllText(HttpContext.Current.Server.MapPath(templateHtmlPath));

テンプレートファイルの中身は以下の通り。まずはテキストメール用。

@Model.Name さん
こんにちは!

次はHTMLメール用。

<html>
<head>
  <title>bizsky ボックス</title>
  <style>
  <!--
    '@'マークを使うときは'@@'と記述する。
  -->
  </style>
</head>
<body>
  <div>@Model.Name さん</div>
  <div>こんにちは!</div>
</body>
</html>

テンプレートをRazorEngineに追加してコンパイルする。

// テンプレート作成
var service = Engine.Razor;
service.AddTemplate("templateHtml", templateHtml);
service.Compile("templateHtml", typeof(Template));
service.AddTemplate("templateText", templateText);
service.Compile("templateText", typeof(Template))

テンプレートにモデルを埋め込んで結合する。

var htmlBody = service.Run("templateHtml", typeof(Template), new Template { Name = "Taro Yamada" });
var textBody = service.Run("templateText", typeof(Template), new Template { Name = "Taro Yamada" });


スタイルを「@Styles.Render()」で埋め込みたかったが対応していないようだ。

New XPS 13が修理から戻ってきた。

修理から戻ってきたのは2週間前。だいたい修理に2週間ぐらいかかった。
修理内容はSSDの交換で、OS入れ直したとなった。

以下、セットアップした内容である。

基本方針

Chocolateyでインストール可能なものは、すべてChocolateyでインストールする。
https://chocolatey.org
なおVimはChocolateyにあるが、32bit版なのでやめておく。

ソフトウェアインストール

Office2013

インストーラーからインストール

GVim

香り屋さんのサイトで64bit版をダウンロードしてインストール
https://www.kaoriya.net/software/vim/

Dein.vim

続きを読む

wslttyを使用したときのホームディレクトリの位置

C:\Users\[Windows User Name]\AppData\Local\lxss\home\[Linux User Name]

エクスプローラーから探しても「lxss」が見つからないので、ホームディレクトリにおいてあるファイルでエクスプローラーから検索をかけて発見した。

余談だがwlsttyの設定ファイル「.minttyrc」は以下のパスに配置してある。

C:\Users\[Windows User Name]\AppData\Local\wsltty\home\[Linux User Name]

わかりづらいよね。

一人会社社長、家を買う。

中古マンションを購入しました。物件引き渡しまでに得た知見を、これから購入しようとしている方へ共有できたらと思います。

対象読者

以下のような方を対象にしています。

  • 持ち家を購入しようと計画している
  • 法人化した経営者
  • 法人化して日が浅い

法人成りしたばかりだと購入は諦めた方がいい

法人成りしてまだ1~2期目の経営者様、持ち家購入は諦めてください。借入額によっては住宅ローン審査に通りません*1。それならば法人で借り入れしようと思っても、法人での借り入れはもっと審査が厳しいです*2
ローン審査ではだいたい3期分の決算報告書が必要です。うちは2期分+3期目の試算表+個人事業主時代の確定申告書3期分を提出しました。
不動産登記書類を作るときに司法書士の方とちらっと話をしましたが、法人成りするとそれまでの収入実績はリセットされるみたいです。仮にサラリーマンとして年収1000万円が数年間続いていたとしても、法人成りした時点で加味されなくなるということです。
これから会社を作ろうとしている方、法人化前に住宅購入を済ませてください。

*1:頭金が物件価格の2割以上あれば違ってくるかもしれないが、法人成りしたばかりだと資本金に自己資金が取られ、頭金はあまり捻出できないと思う

*2:そして金利が高い

続きを読む

BoW(wsltty)のrailsコマンドで「Error: Command 'rails' not recognized」が発生したときの対処法

Bash on Ubuntu on Windows(wsltty)上にrbenvでRoRの環境を作り、rails crails g model hogehogeを実行したら以下のエラーが発生した。

$ rails c
Version: 2.0.1

Usage: spring COMMAND [ARGS]

Commands for spring itself:

  binstub         Generate spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert.
  help            Print available commands.
  server          Explicitly start a Spring server in the foreground
  status          Show current status.
  stop            Stop all spring processes for this project.

Commands for your application:

  rails           Run a rails command. The following sub commands will use spring: console, runner, generate, destroy, test.
  rake            Runs the rake command
Error: Command 'rails' not recognized
Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 plugin new   Generates skeleton for developing a Rails plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")

All commands can be run with -h (or --help) for more information.

直し方は以下のサイトに書いてあった。 stackoverflow.com この質問の回答によると、以下のコマンドを実行すれば良いとのこと。

rake rails:update:bin

無事にrailsコマンドが正常に動作するようになった。

原因だが、Macで作ったRailsプロジェクトをリポジトリから取得して作業したためbin/railsがそのまま使われており、おそらくそれでプラットフォームの違いがあり正常動作しなかったと思われる。