super-pro-kit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/slim-5.2.1/CHANGES +496 -0
- data/slim-5.2.1/Gemfile +43 -0
- data/slim-5.2.1/LICENSE +21 -0
- data/slim-5.2.1/README.jp.md +1276 -0
- data/slim-5.2.1/README.md +1313 -0
- data/slim-5.2.1/Rakefile +80 -0
- data/slim-5.2.1/bin/slimrb +6 -0
- data/slim-5.2.1/doc/include.md +20 -0
- data/slim-5.2.1/doc/jp/include.md +20 -0
- data/slim-5.2.1/doc/jp/logic_less.md +137 -0
- data/slim-5.2.1/doc/jp/smart.md +102 -0
- data/slim-5.2.1/doc/jp/translator.md +28 -0
- data/slim-5.2.1/doc/logic_less.md +137 -0
- data/slim-5.2.1/doc/smart.md +120 -0
- data/slim-5.2.1/doc/translator.md +28 -0
- data/slim-5.2.1/lib/slim/code_attributes.rb +68 -0
- data/slim-5.2.1/lib/slim/command.rb +122 -0
- data/slim-5.2.1/lib/slim/controls.rb +61 -0
- data/slim-5.2.1/lib/slim/do_inserter.rb +34 -0
- data/slim-5.2.1/lib/slim/embedded.rb +248 -0
- data/slim-5.2.1/lib/slim/end_inserter.rb +63 -0
- data/slim-5.2.1/lib/slim/engine.rb +42 -0
- data/slim-5.2.1/lib/slim/erb_converter.rb +15 -0
- data/slim-5.2.1/lib/slim/filter.rb +31 -0
- data/slim-5.2.1/lib/slim/grammar.rb +24 -0
- data/slim-5.2.1/lib/slim/include.rb +58 -0
- data/slim-5.2.1/lib/slim/interpolation.rb +36 -0
- data/slim-5.2.1/lib/slim/logic_less/context.rb +126 -0
- data/slim-5.2.1/lib/slim/logic_less/filter.rb +81 -0
- data/slim-5.2.1/lib/slim/logic_less.rb +6 -0
- data/slim-5.2.1/lib/slim/parser.rb +535 -0
- data/slim-5.2.1/lib/slim/railtie.rb +19 -0
- data/slim-5.2.1/lib/slim/smart/escaper.rb +42 -0
- data/slim-5.2.1/lib/slim/smart/filter.rb +97 -0
- data/slim-5.2.1/lib/slim/smart/parser.rb +35 -0
- data/slim-5.2.1/lib/slim/smart.rb +9 -0
- data/slim-5.2.1/lib/slim/splat/builder.rb +115 -0
- data/slim-5.2.1/lib/slim/splat/filter.rb +93 -0
- data/slim-5.2.1/lib/slim/template.rb +6 -0
- data/slim-5.2.1/lib/slim/translator.rb +119 -0
- data/slim-5.2.1/lib/slim/version.rb +6 -0
- data/slim-5.2.1/lib/slim.rb +16 -0
- data/slim-5.2.1/slim.gemspec +33 -0
- data/slim-5.2.1/test/core/helper.rb +201 -0
- data/slim-5.2.1/test/core/test_code_blocks.rb +194 -0
- data/slim-5.2.1/test/core/test_code_escaping.rb +162 -0
- data/slim-5.2.1/test/core/test_code_evaluation.rb +181 -0
- data/slim-5.2.1/test/core/test_code_output.rb +168 -0
- data/slim-5.2.1/test/core/test_code_structure.rb +203 -0
- data/slim-5.2.1/test/core/test_commands.rb +219 -0
- data/slim-5.2.1/test/core/test_embedded_engines.rb +247 -0
- data/slim-5.2.1/test/core/test_encoding.rb +28 -0
- data/slim-5.2.1/test/core/test_erb_converter.rb +65 -0
- data/slim-5.2.1/test/core/test_html_attributes.rb +276 -0
- data/slim-5.2.1/test/core/test_html_escaping.rb +65 -0
- data/slim-5.2.1/test/core/test_html_structure.rb +599 -0
- data/slim-5.2.1/test/core/test_parser_errors.rb +148 -0
- data/slim-5.2.1/test/core/test_pretty.rb +163 -0
- data/slim-5.2.1/test/core/test_ruby_errors.rb +200 -0
- data/slim-5.2.1/test/core/test_slim_template.rb +78 -0
- data/slim-5.2.1/test/core/test_splat_prefix_option.rb +155 -0
- data/slim-5.2.1/test/core/test_tabs.rb +169 -0
- data/slim-5.2.1/test/core/test_text_interpolation.rb +79 -0
- data/slim-5.2.1/test/core/test_thread_options.rb +18 -0
- data/slim-5.2.1/test/core/test_unicode.rb +15 -0
- data/slim-5.2.1/test/include/files/recursive.slim +1 -0
- data/slim-5.2.1/test/include/files/slimfile.slim +3 -0
- data/slim-5.2.1/test/include/files/subdir/test.slim +1 -0
- data/slim-5.2.1/test/include/files/textfile +1 -0
- data/slim-5.2.1/test/include/test_include.rb +24 -0
- data/slim-5.2.1/test/literate/TESTS.md +1323 -0
- data/slim-5.2.1/test/literate/helper.rb +15 -0
- data/slim-5.2.1/test/literate/run.rb +92 -0
- data/slim-5.2.1/test/logic_less/test_logic_less.rb +330 -0
- data/slim-5.2.1/test/rails/Rakefile +7 -0
- data/slim-5.2.1/test/rails/app/assets/config/manifest.js +1 -0
- data/slim-5.2.1/test/rails/app/controllers/application_controller.rb +2 -0
- data/slim-5.2.1/test/rails/app/controllers/entries_controller.rb +5 -0
- data/slim-5.2.1/test/rails/app/controllers/slim_controller.rb +46 -0
- data/slim-5.2.1/test/rails/app/helpers/application_helper.rb +5 -0
- data/slim-5.2.1/test/rails/app/models/entry.rb +16 -0
- data/slim-5.2.1/test/rails/app/views/entries/edit.html.slim +3 -0
- data/slim-5.2.1/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
- data/slim-5.2.1/test/rails/app/views/layouts/application.html.slim +10 -0
- data/slim-5.2.1/test/rails/app/views/slim/_partial.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/attributes.html.slim +3 -0
- data/slim-5.2.1/test/rails/app/views/slim/content_for.html.slim +7 -0
- data/slim-5.2.1/test/rails/app/views/slim/erb.html.erb +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/form_for.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/helper.html.slim +4 -0
- data/slim-5.2.1/test/rails/app/views/slim/integers.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/no_layout.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/normal.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/partial.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/splat.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/thread_options.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/variables.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/xml.slim +1 -0
- data/slim-5.2.1/test/rails/config/application.rb +44 -0
- data/slim-5.2.1/test/rails/config/boot.rb +10 -0
- data/slim-5.2.1/test/rails/config/environment.rb +5 -0
- data/slim-5.2.1/test/rails/config/environments/test.rb +34 -0
- data/slim-5.2.1/test/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/slim-5.2.1/test/rails/config/initializers/inflections.rb +10 -0
- data/slim-5.2.1/test/rails/config/initializers/mime_types.rb +5 -0
- data/slim-5.2.1/test/rails/config/initializers/session_store.rb +8 -0
- data/slim-5.2.1/test/rails/config/locales/en.yml +5 -0
- data/slim-5.2.1/test/rails/config/routes.rb +60 -0
- data/slim-5.2.1/test/rails/config.ru +4 -0
- data/slim-5.2.1/test/rails/script/rails +6 -0
- data/slim-5.2.1/test/rails/test/helper.rb +34 -0
- data/slim-5.2.1/test/rails/test/test_slim.rb +102 -0
- data/slim-5.2.1/test/sinatra/contest.rb +91 -0
- data/slim-5.2.1/test/sinatra/helper.rb +143 -0
- data/slim-5.2.1/test/sinatra/test_core.rb +91 -0
- data/slim-5.2.1/test/sinatra/test_include.rb +16 -0
- data/slim-5.2.1/test/sinatra/views/embed_include_js.slim +8 -0
- data/slim-5.2.1/test/sinatra/views/embed_js.slim +11 -0
- data/slim-5.2.1/test/sinatra/views/footer.slim +1 -0
- data/slim-5.2.1/test/sinatra/views/hello.slim +1 -0
- data/slim-5.2.1/test/sinatra/views/layout2.slim +3 -0
- data/slim-5.2.1/test/smart/test_smart_text.rb +294 -0
- data/slim-5.2.1/test/translator/test_translator.rb +76 -0
- data/super-pro-kit.gemspec +11 -0
- metadata +165 -0
data/slim-5.2.1/Rakefile
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
rescue Exception
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rake/testtask'
|
|
8
|
+
|
|
9
|
+
task 'test' => %w(test:core test:literate test:logic_less test:translator test:smart test:include)
|
|
10
|
+
|
|
11
|
+
namespace 'test' do
|
|
12
|
+
Rake::TestTask.new('core') do |t|
|
|
13
|
+
t.libs << 'lib' << 'test/core'
|
|
14
|
+
t.test_files = FileList['test/core/test_*.rb']
|
|
15
|
+
t.warning = true
|
|
16
|
+
#t.ruby_opts << '-w' << '-v'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Rake::TestTask.new('literate') do |t|
|
|
20
|
+
t.libs << 'lib' << 'test/literate'
|
|
21
|
+
t.test_files = FileList['test/literate/run.rb']
|
|
22
|
+
t.warning = true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Rake::TestTask.new('logic_less') do |t|
|
|
26
|
+
t.libs << 'lib' << 'test/core'
|
|
27
|
+
t.test_files = FileList['test/logic_less/test_*.rb']
|
|
28
|
+
t.warning = true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Rake::TestTask.new('translator') do |t|
|
|
32
|
+
t.libs << 'lib' << 'test/core'
|
|
33
|
+
t.test_files = FileList['test/translator/test_*.rb']
|
|
34
|
+
t.warning = true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Rake::TestTask.new('smart') do |t|
|
|
38
|
+
t.libs << 'lib' << 'test/core'
|
|
39
|
+
t.test_files = FileList['test/smart/test_*.rb']
|
|
40
|
+
t.warning = true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Rake::TestTask.new('include') do |t|
|
|
44
|
+
t.libs << 'lib' << 'test/core'
|
|
45
|
+
t.test_files = FileList['test/include/test_*.rb']
|
|
46
|
+
t.warning = true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Rake::TestTask.new('rails') do |t|
|
|
50
|
+
t.libs << 'lib'
|
|
51
|
+
t.test_files = FileList['test/rails/test/test_*.rb']
|
|
52
|
+
t.warning = true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
Rake::TestTask.new('sinatra') do |t|
|
|
56
|
+
t.libs << 'lib'
|
|
57
|
+
t.test_files = FileList['test/sinatra/test_*.rb']
|
|
58
|
+
|
|
59
|
+
# Copied from test task in Sinatra project to mimic their approach
|
|
60
|
+
t.ruby_opts = ['-r rubygems'] if defined? Gem
|
|
61
|
+
t.ruby_opts << '-I.'
|
|
62
|
+
t.warning = true
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
begin
|
|
67
|
+
require 'yard'
|
|
68
|
+
YARD::Rake::YardocTask.new do |t|
|
|
69
|
+
t.files = %w(lib/**/*.rb)
|
|
70
|
+
end
|
|
71
|
+
rescue LoadError
|
|
72
|
+
task :yard do
|
|
73
|
+
abort 'YARD is not available. In order to run yard, you must: gem install yard'
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
desc 'Generate Documentation'
|
|
78
|
+
task doc: :yard
|
|
79
|
+
|
|
80
|
+
task default: 'test'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Include
|
|
2
|
+
|
|
3
|
+
The include plugin allows Slim templates to include other files. The .slim extension is appended automatically to the
|
|
4
|
+
filename. If the included file is not a Slim file, it is interpreted as a text file with `#{interpolation}`.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
|
|
8
|
+
include partial.slim
|
|
9
|
+
include partial
|
|
10
|
+
include partial.txt
|
|
11
|
+
|
|
12
|
+
Enable the include plugin with
|
|
13
|
+
|
|
14
|
+
require 'slim/include'
|
|
15
|
+
|
|
16
|
+
# Options
|
|
17
|
+
|
|
18
|
+
| Type | Name | Default | Purpose |
|
|
19
|
+
| ---- | ---- | ------- | ------- |
|
|
20
|
+
| Array | :include_dirs | [Dir.pwd, '.'] | Directories where to look for the files |
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# インクルード
|
|
2
|
+
|
|
3
|
+
インクルードプラグインを使うことで, Slim テンプレートに他の Slim ファイルを読み込むことができます。.slim 拡張子はファイル名に自動的に付加されます。
|
|
4
|
+
読み込まれたファイルが Slim でない場合は `#{文字列展開}` を含んだテキストファイルとして扱われます。
|
|
5
|
+
|
|
6
|
+
例:
|
|
7
|
+
|
|
8
|
+
include partial.slim
|
|
9
|
+
include partial
|
|
10
|
+
include partial.txt
|
|
11
|
+
|
|
12
|
+
インクルードプラグインを有効化
|
|
13
|
+
|
|
14
|
+
require 'slim/include'
|
|
15
|
+
|
|
16
|
+
# オプション
|
|
17
|
+
|
|
18
|
+
| タイプ | 名前 | デフォルト値 | 目的 |
|
|
19
|
+
| ------ | ---- | ------------ | ---- |
|
|
20
|
+
| Array | :include_dirs | [Dir.pwd, '.'] | ファイルを検索するディレクトリ |
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# ロジックレスモード
|
|
2
|
+
|
|
3
|
+
ロジックレスモードは [Mustache](https://github.com/defunkt/mustache) にインスパイアされています。ロジックレスモードは
|
|
4
|
+
例えば動的コンテンツを含む再帰的ハッシュツリーのような辞書オブジェクトを使います。
|
|
5
|
+
|
|
6
|
+
## 条件付き
|
|
7
|
+
|
|
8
|
+
オブジェクトが false または empty? ではない場合, コンテンツが表示されます。
|
|
9
|
+
|
|
10
|
+
- article
|
|
11
|
+
h1 = title
|
|
12
|
+
|
|
13
|
+
## 反転条件付き
|
|
14
|
+
|
|
15
|
+
オブジェクトが false または empty? の場合, コンテンツが表示されます。
|
|
16
|
+
|
|
17
|
+
-! article
|
|
18
|
+
p Sorry, article not found
|
|
19
|
+
|
|
20
|
+
## 繰り返し
|
|
21
|
+
|
|
22
|
+
オブジェクトが配列の場合, この部分は繰り返されます。
|
|
23
|
+
|
|
24
|
+
- articles
|
|
25
|
+
tr: td = title
|
|
26
|
+
|
|
27
|
+
## ラムダ式
|
|
28
|
+
|
|
29
|
+
Mustache のように, Slim はラムダ式をサポートします。
|
|
30
|
+
|
|
31
|
+
= person
|
|
32
|
+
= name
|
|
33
|
+
|
|
34
|
+
ラムダ式は次のように定義できます:
|
|
35
|
+
|
|
36
|
+
def lambda_method
|
|
37
|
+
"<div class='person'>#{yield(name: 'Andrew')}</div>"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
任意に 1 つ以上のハッシュを `yield` に渡すことができます。複数のハッシュを渡した場合, 先述したようにブロックが繰り返されます。
|
|
41
|
+
|
|
42
|
+
## 辞書アクセス
|
|
43
|
+
|
|
44
|
+
サンプルコード:
|
|
45
|
+
|
|
46
|
+
- article
|
|
47
|
+
h1 = title
|
|
48
|
+
|
|
49
|
+
辞書オブジェクトは `:dictionary_access` オプションによって設定された順序でアクセスされます。デフォルトの順序:
|
|
50
|
+
|
|
51
|
+
1. `シンボル` - `article.respond_to?(:has_key?)` 且つ `article.has_key?(:title)` の場合, Slim は `article[:title]` を実行します。
|
|
52
|
+
2. `文字列` - `article.respond_to?(:has_key?)` 且つ `article.has_key?('title')` の場合, Slim は `article['title']` を実行します。
|
|
53
|
+
3. `メソッド` - `article.respond_to?(:title)` の場合, Slim は `article.send(:title)` を実行します。
|
|
54
|
+
4. `インスタンス変数` - `article.instance_variable_defined?(@title)` の場合, Slim は `article.instance_variable_get @title` を実行します。
|
|
55
|
+
|
|
56
|
+
すべて失敗した場合, Slim は親オブジェクトに対して同じ順序で title の参照を解決しようとします。この例では, 親オブジェクトはレンダリングしているテンプレートに対する辞書オブジェクトになります。
|
|
57
|
+
|
|
58
|
+
ご想像のとおり, article への参照は辞書オブジェクトに対して同じ手順で行われます。インスタンス変数はビューのコードでは利用を許されていませんが, Slim はそれを見つけて使います。基本的には, テンプレートの中で @ プレフィックスを落として使っています。パラメータ付きメソッドの呼び出しは許可されません。
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## 文字列
|
|
62
|
+
|
|
63
|
+
`self` キーワードは検討中の要素を `.to_s` した値を返します。
|
|
64
|
+
|
|
65
|
+
辞書オブジェクトを与え,
|
|
66
|
+
|
|
67
|
+
{
|
|
68
|
+
article: [
|
|
69
|
+
'Article 1',
|
|
70
|
+
'Article 2'
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
ビューで次のように
|
|
75
|
+
|
|
76
|
+
- article
|
|
77
|
+
tr: td = self
|
|
78
|
+
|
|
79
|
+
これは次のようになります。
|
|
80
|
+
|
|
81
|
+
<tr>
|
|
82
|
+
<td>Article 1</td>
|
|
83
|
+
</>
|
|
84
|
+
<tr>
|
|
85
|
+
<td>Article 2</td>
|
|
86
|
+
</tr>
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Rails でロジックレスモード
|
|
90
|
+
|
|
91
|
+
インストール:
|
|
92
|
+
|
|
93
|
+
$ gem install slim
|
|
94
|
+
|
|
95
|
+
require で指定:
|
|
96
|
+
|
|
97
|
+
gem 'slim', require: 'slim/logic_less'
|
|
98
|
+
|
|
99
|
+
特定のアクションでのみロジックレスモードを有効化したい場合, まず設定でロジックレスモードを global に無効化します。
|
|
100
|
+
|
|
101
|
+
Slim::Engine.set_options logic_less: false
|
|
102
|
+
|
|
103
|
+
さらに, アクションの中でレンダリングする度にロジックレスモードを有効化します。
|
|
104
|
+
|
|
105
|
+
class Controller
|
|
106
|
+
def action
|
|
107
|
+
Slim::Engine.with_options(logic_less: true) do
|
|
108
|
+
render
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
## Sinatra でロジックレスモード
|
|
114
|
+
|
|
115
|
+
Sinatra には Slim のビルトインサポートがあります。しなければならないのはロジックレス Slim プラグインを require することです。config.ru で require できます:
|
|
116
|
+
|
|
117
|
+
require 'slim/logic_less'
|
|
118
|
+
|
|
119
|
+
これで準備は整いました!
|
|
120
|
+
|
|
121
|
+
特定のアクションでのみロジックレスモードを有効化したい場合, まず設定でロジックレスモードを global に無効化します。
|
|
122
|
+
|
|
123
|
+
Slim::Engine.set_options logic_less: false
|
|
124
|
+
|
|
125
|
+
さらに, アクションの中でレンダリングする度にロジックレスモードを有効化します。
|
|
126
|
+
|
|
127
|
+
get '/page'
|
|
128
|
+
slim :page, logic_less: true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
## オプション
|
|
132
|
+
|
|
133
|
+
| 種類 | 名前 | デフォルト | 用途 |
|
|
134
|
+
| ---- | ---- | ------- | ------- |
|
|
135
|
+
| 真偽値 | :logic_less | true | ロジックレスモードを有効化 ('slim/logic_less' の required が必要) |
|
|
136
|
+
| 文字列 | :dictionary | "self" | 変数が検索される辞書への参照 |
|
|
137
|
+
| シンボル/配列<シンボル> | :dictionary_access | [:symbol, :string, :method, :instance_variable] | 辞書のアクセス順序 (:symbol, :string, :method, :instance_variable) |
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# スマートテキスト
|
|
2
|
+
|
|
3
|
+
テキストとマークアップを組み合わせる最も簡単な方法は <a name="smarttext">スマートテキストモード</a> を使うことです。
|
|
4
|
+
|
|
5
|
+
スマートテキストプラグインを有効化します。
|
|
6
|
+
|
|
7
|
+
require 'slim/smart'
|
|
8
|
+
|
|
9
|
+
自動的に `:implicit_text` オプションが有効になることで,
|
|
10
|
+
次のように簡単にテキストを入力できるようになります:
|
|
11
|
+
|
|
12
|
+
p
|
|
13
|
+
This is text.
|
|
14
|
+
|
|
15
|
+
小文字のタグ名や暗黙的なテキスト行などの特殊文字で始まっていない行を
|
|
16
|
+
Slim に自動的に処理させることができます。
|
|
17
|
+
テキストが複数行にわたる場合, 単にそれらをインデントします。
|
|
18
|
+
|
|
19
|
+
p
|
|
20
|
+
This is text,
|
|
21
|
+
and it spans
|
|
22
|
+
several lines.
|
|
23
|
+
|
|
24
|
+
`>` を使って明示的にテキストをマークすることもできます。
|
|
25
|
+
例えば, 小文字や特殊文字で始まっている場合,
|
|
26
|
+
テキストが複数行にわたる場合,
|
|
27
|
+
単に見た目の一貫性のために,
|
|
28
|
+
タグ名に大文字を使いたい場合,
|
|
29
|
+
`:implicit_text` オプションを無効にしたままにする必要がある場合です。
|
|
30
|
+
|
|
31
|
+
p
|
|
32
|
+
> 'This is text, too.'
|
|
33
|
+
p
|
|
34
|
+
>
|
|
35
|
+
This is text
|
|
36
|
+
which spans
|
|
37
|
+
several lines.
|
|
38
|
+
|
|
39
|
+
`:smart_text_escaping` が有効化されている限り,
|
|
40
|
+
エスケープされるべきテキストは自動的にエスケープされます。
|
|
41
|
+
しかし, 不便にならないように検出された HTML エンティティはそのまま使われます。
|
|
42
|
+
この方法はいつでも HTML のエスケープを気にすることのない,
|
|
43
|
+
最も理想的な方法です。
|
|
44
|
+
|
|
45
|
+
h1 Questions & Answers
|
|
46
|
+
footer
|
|
47
|
+
Copyright © #{Time.now.year}
|
|
48
|
+
|
|
49
|
+
スマートテキストの素晴らしいところの 1 つはマークアップとよくミックスしているところです。
|
|
50
|
+
スマートテキストの行は通常改行を維持するので,
|
|
51
|
+
強調やリンクのような他のタグを簡単に混ぜ合わせて使うことができます:
|
|
52
|
+
|
|
53
|
+
p
|
|
54
|
+
Your credit card
|
|
55
|
+
strong will not
|
|
56
|
+
> be charged now.
|
|
57
|
+
p
|
|
58
|
+
Check
|
|
59
|
+
a href=r(:faq) our FAQ
|
|
60
|
+
> for more info.
|
|
61
|
+
|
|
62
|
+
(タグから小文字のテキストを区別する場合明示的なテキストを示すインジケーター `>` の使用には注意してください)。
|
|
63
|
+
|
|
64
|
+
インラインタグのまわりにスペースを入れたくない場合があります。
|
|
65
|
+
幸いなことにスマートテキストはこの一般的なケースを処理できます。
|
|
66
|
+
スマートテキストのブロックが `:smart_text_begin_chars` で指定 (デフォルトは `,.;:!?)]}`)
|
|
67
|
+
された文字で始まる場合には先頭の改行が行われません。
|
|
68
|
+
同様に, スマートテキストのブロックが `:smart_text_begin_chars` で指定 (デフォルトは `,.;:!?)]}`)
|
|
69
|
+
された文字で終わる場合には改行されません。
|
|
70
|
+
これによって通常のテキストとリンクや span タグを混在させることがとても容易になります:
|
|
71
|
+
|
|
72
|
+
p
|
|
73
|
+
Please proceed to
|
|
74
|
+
a href="/" our homepage
|
|
75
|
+
.
|
|
76
|
+
p
|
|
77
|
+
Status: failed (
|
|
78
|
+
a href="#1" details
|
|
79
|
+
).
|
|
80
|
+
|
|
81
|
+
スマートテキストはタグのショートカットをも把握しているので,
|
|
82
|
+
次のような場合にも正しく対応します:
|
|
83
|
+
|
|
84
|
+
.class
|
|
85
|
+
#id
|
|
86
|
+
#{'More'}
|
|
87
|
+
i text
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
当然のことながら, これは短いテキストのスニペットでより便利に作業できることを意味しています。
|
|
91
|
+
ほとんどがテキストのコンテンツの場合, Markdown や Textile のような
|
|
92
|
+
ビルトインの埋め込みエンジンを使う方が良いでしょう。
|
|
93
|
+
|
|
94
|
+
## オプション
|
|
95
|
+
|
|
96
|
+
| 種類 | 名前 | デフォルト | 用途 |
|
|
97
|
+
| ---- | ---- | ---------- | ---- |
|
|
98
|
+
| 真偽値 | :implicit_text | true | 暗黙的テキストの判別を有効化 |
|
|
99
|
+
| 真偽値 | :smart_text | true | スマートテキストによる処理を有効化 |
|
|
100
|
+
| 文字列 | :smart_text_begin_chars | ',.;:!?)]}' | スマートテキストで先頭の改行を抑制する文字 |
|
|
101
|
+
| 文字列 | :smart_text_end_chars | '([{' | スマートテキストで末尾の改行を抑制する文字 |
|
|
102
|
+
| 真偽値 | :smart_text_escaping | true | 設定すると, スマートテキスト中のエスケープが必要な HTML 文字は自動的にエスケープされる |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 翻訳/I18n
|
|
2
|
+
|
|
3
|
+
翻訳プラグインは Gettext, Fast-Gettext または Rails I18n を使ったテンプレートの自動翻訳機能を提供します。
|
|
4
|
+
テンプレート内の静的テキストを翻訳版に変換します。
|
|
5
|
+
|
|
6
|
+
例:
|
|
7
|
+
|
|
8
|
+
h1 Welcome to #{url}!
|
|
9
|
+
|
|
10
|
+
Gettext は文字列を英語からドイツ語に変換し, 文字列が展開される部分は %1, %2, ... の順に変換されます。
|
|
11
|
+
|
|
12
|
+
"Welcome to %1!" -> "Willkommen auf %1!"
|
|
13
|
+
|
|
14
|
+
次のようにレンダリングされます。
|
|
15
|
+
|
|
16
|
+
<h1>Willkommen auf github.com/slim-template/slim!</h1>
|
|
17
|
+
|
|
18
|
+
翻訳プラグインを有効化します。
|
|
19
|
+
|
|
20
|
+
require 'slim/translator'
|
|
21
|
+
|
|
22
|
+
# オプション
|
|
23
|
+
|
|
24
|
+
| 種類 | 名前 | デフォルト | 用途 |
|
|
25
|
+
| ---- | ---- | ---------- | ---- |
|
|
26
|
+
| 真偽値 | :tr | true | 翻訳の有効化 ('slim/translator' の required が必要) |
|
|
27
|
+
| シンボル | :tr_mode | :dynamic | 翻訳を :static = コンパイル時に実施, :dynamic = ランタイムで実施 |
|
|
28
|
+
| 文字列 | :tr_fn | インストールされた翻訳ライブラリに依存 | 翻訳用ヘルパ, gettext の場合 '_' |
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Logic less mode
|
|
2
|
+
|
|
3
|
+
Logic less mode is inspired by [Mustache](https://github.com/defunkt/mustache). Logic less mode uses a dictionary object
|
|
4
|
+
e.g. a recursive hash tree which contains the dynamic content.
|
|
5
|
+
|
|
6
|
+
## Conditional
|
|
7
|
+
|
|
8
|
+
If the object is not false or empty?, the content will show
|
|
9
|
+
|
|
10
|
+
- article
|
|
11
|
+
h1 = title
|
|
12
|
+
|
|
13
|
+
## Inverted conditional
|
|
14
|
+
|
|
15
|
+
If the object is false or empty?, the content will show
|
|
16
|
+
|
|
17
|
+
-! article
|
|
18
|
+
p Sorry, article not found
|
|
19
|
+
|
|
20
|
+
## Iteration
|
|
21
|
+
|
|
22
|
+
If the object is an array, the section will iterate
|
|
23
|
+
|
|
24
|
+
- articles
|
|
25
|
+
tr: td = title
|
|
26
|
+
|
|
27
|
+
## Lambdas
|
|
28
|
+
|
|
29
|
+
Like mustache, Slim supports lambdas.
|
|
30
|
+
|
|
31
|
+
= person
|
|
32
|
+
= name
|
|
33
|
+
|
|
34
|
+
The lambda method could be defined like this
|
|
35
|
+
|
|
36
|
+
def lambda_method
|
|
37
|
+
"<div class='person'>#{yield(name: 'Andrew')}</div>"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
You can optionally pass one or more hashes to `yield`. If you pass multiple hashes, the block will be iterated as described above.
|
|
41
|
+
|
|
42
|
+
## Dictionary access
|
|
43
|
+
|
|
44
|
+
Example code:
|
|
45
|
+
|
|
46
|
+
- article
|
|
47
|
+
h1 = title
|
|
48
|
+
|
|
49
|
+
The dictionary object is accessed in the order given by the `:dictionary_access`. Default order:
|
|
50
|
+
|
|
51
|
+
1. `:symbol` - If `article.respond_to?(:has_key?)` and `article.has_key?(:title)`, Slim will execute `article[:title]`
|
|
52
|
+
2. `:string` - If `article.respond_to?(:has_key?)` and `article.has_key?('title')`, Slim will execute `article['title']`
|
|
53
|
+
3. `:method` - If `article.respond_to?(:title)`, Slim will execute `article.send(:title)`
|
|
54
|
+
4. `:instance_variable` - If `article.instance_variable_defined?(@title)`, Slim will execute `article.instance_variable_get @title`
|
|
55
|
+
|
|
56
|
+
If all the above fails, Slim will try to resolve the title reference in the same order against the parent object. In this example, the parent would be the dictionary object you are rendering the template against.
|
|
57
|
+
|
|
58
|
+
As you might have guessed, the article reference goes through the same steps against the dictionary. Instance variables are not allowed in the view code, but Slim will find and use them. Essentially, you're just dropping the @ prefix in your template. Parameterized method calls are not allowed.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Strings
|
|
62
|
+
|
|
63
|
+
The `self` keyword will return the `.to_s` value for the element under consideration.
|
|
64
|
+
|
|
65
|
+
Given
|
|
66
|
+
|
|
67
|
+
{
|
|
68
|
+
article: [
|
|
69
|
+
'Article 1',
|
|
70
|
+
'Article 2'
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
And
|
|
75
|
+
|
|
76
|
+
- article
|
|
77
|
+
tr: td = self
|
|
78
|
+
|
|
79
|
+
This will yield
|
|
80
|
+
|
|
81
|
+
<tr>
|
|
82
|
+
<td>Article 1</td>
|
|
83
|
+
</tr>
|
|
84
|
+
<tr>
|
|
85
|
+
<td>Article 2</td>
|
|
86
|
+
</tr>
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Logic less in Rails
|
|
90
|
+
|
|
91
|
+
Install:
|
|
92
|
+
|
|
93
|
+
$ gem install slim
|
|
94
|
+
|
|
95
|
+
Require:
|
|
96
|
+
|
|
97
|
+
gem 'slim', require: 'slim/logic_less'
|
|
98
|
+
|
|
99
|
+
You might want to activate logic less mode only for a few actions, you should disable logic-less mode globally at first in the configuration
|
|
100
|
+
|
|
101
|
+
Slim::Engine.set_options logic_less: false
|
|
102
|
+
|
|
103
|
+
and activate logic less mode per render call in your action
|
|
104
|
+
|
|
105
|
+
class Controller
|
|
106
|
+
def action
|
|
107
|
+
Slim::Engine.with_options(logic_less: true) do
|
|
108
|
+
render
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
## Logic less in Sinatra
|
|
114
|
+
|
|
115
|
+
Sinatra has built-in support for Slim. All you have to do is require the logic less Slim plugin. This can be done in your config.ru:
|
|
116
|
+
|
|
117
|
+
require 'slim/logic_less'
|
|
118
|
+
|
|
119
|
+
You are then ready to rock!
|
|
120
|
+
|
|
121
|
+
You might want to activate logic less mode only for a few actions, you should disable logic-less mode globally at first in the configuration
|
|
122
|
+
|
|
123
|
+
Slim::Engine.set_options logic_less: false
|
|
124
|
+
|
|
125
|
+
and activate logic less mode per render call in your application
|
|
126
|
+
|
|
127
|
+
get '/page'
|
|
128
|
+
slim :page, logic_less: true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
## Options
|
|
132
|
+
|
|
133
|
+
| Type | Name | Default | Purpose |
|
|
134
|
+
| ---- | ---- | ------- | ------- |
|
|
135
|
+
| Boolean | :logic_less | true | Enable logic less mode (Enabled if 'slim/logic_less' is required) |
|
|
136
|
+
| String | :dictionary | "self" | Dictionary where variables are looked up |
|
|
137
|
+
| Symbol/Array<Symbol> | :dictionary_access | [:symbol, :string, :method, :instance_variable] | Dictionary access order (:symbol, :string, :method, :instance_variable) |
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Smart text
|
|
2
|
+
|
|
3
|
+
The <a name="smarttext">smart text plugin</a> was created to simplify the typing and combining of text and markup in Slim templates.
|
|
4
|
+
Using the plugin gives you:
|
|
5
|
+
|
|
6
|
+
* More convenient ways to type text in Slim templates.
|
|
7
|
+
* Smarter and more consistent HTML escaping of typed text.
|
|
8
|
+
* Easier combining of the text with inline HTML tags with smart handling of whitespace on the boundaries.
|
|
9
|
+
|
|
10
|
+
To get started, enable the smart text plugin with
|
|
11
|
+
|
|
12
|
+
require 'slim/smart'
|
|
13
|
+
|
|
14
|
+
First of all, this automatically enables the `:implicit_text` option.
|
|
15
|
+
When enabled, Slim will treat any line which doesn't start
|
|
16
|
+
with a lowercase tag name or any of the special characters as an implicit text line.
|
|
17
|
+
If the text needs to span several lines, indent them as usual.
|
|
18
|
+
|
|
19
|
+
This allows you to easily type text like this, without any leading indicator:
|
|
20
|
+
|
|
21
|
+
This is an implicit text.
|
|
22
|
+
This is a text
|
|
23
|
+
which spans
|
|
24
|
+
several lines.
|
|
25
|
+
This is yet another text.
|
|
26
|
+
|
|
27
|
+
This works in addition to ways already available in stock Slim:
|
|
28
|
+
|
|
29
|
+
p This is an inline text.
|
|
30
|
+
p This is an inline text
|
|
31
|
+
which spans multiple lines.
|
|
32
|
+
| This is a verbatim text.
|
|
33
|
+
| This is a verbatim text
|
|
34
|
+
which spans multiple lines.
|
|
35
|
+
<p>This is in fact a verbatim text as well.</p>
|
|
36
|
+
|
|
37
|
+
You can also mark the text explicitly with a leading `>`.
|
|
38
|
+
This is used for example when the text starts with a lowercase letter or an unusual character,
|
|
39
|
+
or merely for aesthetic consistency when it spans several lines.
|
|
40
|
+
It may be also needed if you want to use uppercase tag names
|
|
41
|
+
and therefore need to keep the `:implicit_text` option disabled.
|
|
42
|
+
|
|
43
|
+
> This is an explicit text.
|
|
44
|
+
> This is an explicit text
|
|
45
|
+
which spans
|
|
46
|
+
several lines.
|
|
47
|
+
> 'This is a text, too.'
|
|
48
|
+
|
|
49
|
+
> This is another way
|
|
50
|
+
> of typing text which spans
|
|
51
|
+
> several lines, if you prefer that.
|
|
52
|
+
|
|
53
|
+
BTW, all these examples can be pasted to `slimrb -r slim/smart` to see how the generated output looks like.
|
|
54
|
+
|
|
55
|
+
The plugin also improves upon Slim's automatic HTML escaping.
|
|
56
|
+
As long as you leave the `:smart_text_escaping` enabled,
|
|
57
|
+
any non-verbatim text (i.e., any implicit, explicit, and inline text) is automatically escaped for you.
|
|
58
|
+
However, for your convenience, any HTML entities detected are still used verbatim.
|
|
59
|
+
This way you are most likely to get what you really wanted,
|
|
60
|
+
without having to worry about HTML escaping all the time.
|
|
61
|
+
|
|
62
|
+
h1 Questions & Answers
|
|
63
|
+
footer
|
|
64
|
+
Copyright © #{Time.now.year}
|
|
65
|
+
|
|
66
|
+
Another cool thing about the plugin is that it makes text mix fairly well with markup.
|
|
67
|
+
The text lines are made to preserve newlines as needed,
|
|
68
|
+
so it is easy to mix them with other tags, like emphasis or links:
|
|
69
|
+
|
|
70
|
+
p
|
|
71
|
+
Your credit card
|
|
72
|
+
strong will not
|
|
73
|
+
> be charged now.
|
|
74
|
+
p
|
|
75
|
+
Check
|
|
76
|
+
a href='/faq' our FAQ
|
|
77
|
+
> for more info.
|
|
78
|
+
|
|
79
|
+
(Note the use of the explicit text indicator `>` to distinguish lowercase text from tags).
|
|
80
|
+
|
|
81
|
+
However, sometimes you do not want any whitespace around the inline tag at all.
|
|
82
|
+
Fortunately the plugin takes care of the most common cases for you as well.
|
|
83
|
+
The newline before the tag is suppressed if the preceding line ends
|
|
84
|
+
with a character from the `:smart_text_end_chars` set (`([{` by default).
|
|
85
|
+
Similarly, the newline after the tag is suppressed if the following line begins
|
|
86
|
+
with a character from the `:smart_text_begin_chars` set (`,.;:!?)]}` by default).
|
|
87
|
+
This makes it quite easy to naturally mix normal text with links or spans like this:
|
|
88
|
+
|
|
89
|
+
p
|
|
90
|
+
Please proceed to
|
|
91
|
+
a href="/" our homepage
|
|
92
|
+
.
|
|
93
|
+
p
|
|
94
|
+
Status: failed (
|
|
95
|
+
a href="#1" see details
|
|
96
|
+
).
|
|
97
|
+
|
|
98
|
+
Note that the plugin is smart enough to know about tag shortcuts, too,
|
|
99
|
+
so it will correctly deal even with cases like this:
|
|
100
|
+
|
|
101
|
+
.class
|
|
102
|
+
#id
|
|
103
|
+
#{'More'}
|
|
104
|
+
i text
|
|
105
|
+
...
|
|
106
|
+
|
|
107
|
+
And that's it.
|
|
108
|
+
Of course, all this is meant only to make working with short text snippets more convenient.
|
|
109
|
+
For bulk text content, you are more than welcome to use one of the builtin embedded engines,
|
|
110
|
+
such as Markdown or Textile.
|
|
111
|
+
|
|
112
|
+
## Options
|
|
113
|
+
|
|
114
|
+
| Type | Name | Default | Purpose |
|
|
115
|
+
| ---- | ---- | ------- | ------- |
|
|
116
|
+
| Boolean | :implicit_text | true | Enable implicit text recognition |
|
|
117
|
+
| Boolean | :smart_text | true | Enable smart text mode newline processing |
|
|
118
|
+
| String | :smart_text_begin_chars | ',.;:!?)]}' | Characters suppressing leading newline in smart text |
|
|
119
|
+
| String | :smart_text_end_chars | '([{' | Characters suppressing trailing newline in smart text |
|
|
120
|
+
| Boolean | :smart_text_escaping | true | When set, HTML characters which need escaping are automatically escaped in smart text |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Translator/I18n
|
|
2
|
+
|
|
3
|
+
The translator plugin provides automatic translation of the templates using Gettext, Fast-Gettext or Rails I18n. Static text
|
|
4
|
+
in the template is replaced by the translated version.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
|
|
8
|
+
h1 Welcome to #{url}!
|
|
9
|
+
|
|
10
|
+
Gettext translates the string from english to german where interpolations are replaced by %1, %2, ...
|
|
11
|
+
|
|
12
|
+
"Welcome to %1!" -> "Willkommen auf %1!"
|
|
13
|
+
|
|
14
|
+
and renders as
|
|
15
|
+
|
|
16
|
+
<h1>Willkommen auf github.com/slim-template/slim!</h1>
|
|
17
|
+
|
|
18
|
+
Enable the translator plugin with
|
|
19
|
+
|
|
20
|
+
require 'slim/translator'
|
|
21
|
+
|
|
22
|
+
# Options
|
|
23
|
+
|
|
24
|
+
| Type | Name | Default | Purpose |
|
|
25
|
+
| ---- | ---- | ------- | ------- |
|
|
26
|
+
| Boolean | :tr | true | Enable translator (Enabled if 'slim/translator' is required) |
|
|
27
|
+
| Symbol | :tr_mode | :dynamic | When to translate: :static = at compile time, :dynamic = at runtime |
|
|
28
|
+
| String | :tr_fn | Depending on installed translation library | Translation function, could be '_' for gettext |
|