履歴: プログラミング/Riot.js/riot_js-railsの手直し

各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 18 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます

日時タイトル文字数追加削除内容差分基準
2017/1/27 17:22:19プログラミング/Riot.js/riot_js-railsの手直し 最新版25,291+1 -1表示差分—
2017/1/27 17:22:19プログラミング/Riot.js/riot_js-railsの手直し 25,297+2 -1表示表示中選択
2016/10/20 14:32:50プログラミング/Riot.js/riot_js-railsの手直し 25,270+2 -0表示差分選択
2016/10/20 3:05:00プログラミング/Riot.js/riot_js-railsの手直し 25,217+114 -0表示差分選択
2016/10/19 7:15:34プログラミング/Riot.js/riot_js-railsの手直し 21,920+89 -14表示差分選択
2016/10/13 7:49:10プログラミング/Riot.js/riot_js-railsの手直し 19,598+47 -0表示差分基準
2016/10/13 7:49:10プログラミング/Riot.js/riot_js-railsの手直し 18,578+41 -248表示差分選択
2016/10/12 14:57:28プログラミング/Riot.js/riot_js-railsの手直し 23,370+6 -0表示差分選択
2016/10/12 9:36:40プログラミング/Riot.js/riot_js-railsの手直し 23,261+299 -136表示差分選択
2016/10/11 23:52:46プログラミング/Riot.js/riot_js-railsの手直し 18,982+85 -11表示差分選択
2016/10/11 15:58:58プログラミング/Riot.js/riot_js-railsの手直し 17,450+83 -19表示差分選択
2016/10/11 13:50:49プログラミング/Riot.js/riot_js-railsの手直し 15,197+193 -2表示差分選択
2016/10/4 4:45:38プログラミング/Riot.js/riot_js-railsの手直し 11,053+5 -5表示差分選択
2016/10/4 4:45:38プログラミング/Riot.js/riot_js-railsの手直し 11,053+13 -2表示差分選択
2016/10/4 0:29:17プログラミング/Riot.js/riot_js-railsの手直し 10,750+66 -0表示差分選択
2016/7/4 14:28:19プログラミング/Riot.js/riot_js-railsの手直し 8,851+4 -1表示差分選択
2016/7/4 14:28:19プログラミング/Riot.js/riot_js-railsの手直し 8,794+189 -2表示差分選択
2016/7/4 10:47:00プログラミング/Riot.js/riot_js-railsの手直し 3,926— —表示—選択

基準: プログラミング/Riot.js/riot_js-railsの手直し (2016/10/13 7:49:10) → 比較: プログラミング/Riot.js/riot_js-railsの手直し (2017/1/27 17:22:19)

@@ -663,9 +663,11 @@
とすれば上記コードを使えます。
+→ 本家に取り込まれました (2017/01/27)
+
* さらに手直し [#afdb6fc3]
-テストを phantomjs で書いてみる。
+** テストを phantomjs で書いてみる [#g282f17e]
phantomjs の導入は、バイナリをとってくればすぐできる。
@@ -689,27 +691,217 @@
test.js
LANG:js
- var page = require('webpage').create();
+ (function(){
- page.onConsoleMessage = function(msg) { console.log(msg); };
+ var page = require("webpage").create();
+ page.viewportSize = {width: 1024, height: 768};
- page.open('http://localhost:3000/', function(status) {
- if (status === "success") {
- page.evaluate(function() {
- console.log(document.body.innerText.trim());
- });
- phantom.exit(0);
- } else {
- phantom.exit(1);
- }
- });
+ page.onConsoleMessage = function(msg) {
+ console.log(msg);
+ };
+
+ page.open("http://localhost:3000/", function(status) {
+ if (status === "success") {
+ var error = null;
+ page.evaluate(function() {
+ var expected = "<test> tag is working.\n" +
+ "<haml-test> tag is working.\n" +
+ "<slim-test> tag is working.";
+ var result = document.body.innerText.trim();
+ if(result != expected){
+ error = "Failed!\nresult:\n" + result + "\n";
+ }
+ });
+ if(error) {
+ console.log(error);
+ phantom.exit(1);
+ }else {
+ console.log("Success!");
+ phantom.exit(0);
+ }
+ } else {
+ phantom.exit(1);
+ }
+ });
+
+ })();
-などというのを用意しておいて、
+などというスクリプトを用意して、
$ phantomjs test.js
で実行できる。
+** slim も扱えるようにする [#de8e3281]
+
+haml もいいのだけれど、haml + coffee + sass だと、haml と sass の相性が悪いことに気づきました。
+
+slim はタグの前の % がいらないので、sass との相性がよさそう。
+
+class Processer に
+
+ LANG:ruby
+ def self.register_nested(app, config, type, charset, tilt_template)
+ extention = '.' + type
+ if config.respond_to?(:assets)
+ config.assets.configure do |env|
+ if env.respond_to?(:register_transformer)
+ # Sprockets 3 and 4
+ env.register_mime_type 'text/riot-tag+'+type, extensions: ['.tag'+extention], charset: charset
+ env.register_transformer 'text/riot-tag+'+type, 'application/javascript',
+ Proc.new{ |input| Processor.call(tilt_template.new{input[:data]}.render) }
+ elsif env.respond_to?(:register_engine)
+ if Sprockets::VERSION.start_with?("3")
+ # Sprockets 3 ... is this needed?
+ env.register_engine extention, tilt_template, { silence_deprecation: true }
+ else
+ # Sprockets 2.12.4
+ env.register_engine extention, tilt_template
+ end
+ end
+ end
+ else
+ # Sprockets 2
+ app.assets.register_engine extention, tilt_template
+ end
+ end
+
+を用意して、
+
+ LANG:ruby
+ if defined?(::Haml)
+ require 'tilt/haml'
+ Haml::Template.options[:format] = :html5
+ Processor.register_nested(app, config, 'haml', :html, ::Tilt::HamlTemplate)
+ end
+
+ if defined?(::Slim)
+ Processor.register_nested(app, config, 'slim', :html, ::Slim::Template)
+ end
+ end
+
+のようにして登録したところ、slim も使えるようになった。
+
+rails 4 では(?) slim-rails を導入していれば何もしなくても slim がつかえるようだったが、
+上記コードにより slim-rails を Gemfile に含める必要はなく、slim のみでよくなる。
+
+* slim + coffeescript + sass + riot の使い勝手 [#yfd84c69]
+
+** 属性の引用符 [#v88d605f]
+
+riot で属性を javascript で与える場合、引用符を省略して次のように書けますが、
+
+ LANG: html
+ <li each={ item, i in items }>{ item }</li>
+
+slim で
+
+ LANG: slim
+ li each={ item, i in items }
+ | { item }
+
+と書くと属性値の { } の中を ruby で解釈しようとしてエラーになってしまいます。
+
+属性値は必ず引用符で囲まなければなりません。
+
+ LANG: slim
+ li each="{ item, i in items }"
+ | { item }
+
+** style scoped [#ee4334fe]
+
+もしかして、、、これ実現不可能???
+
+** sass 中で改行のエスケープ [#z39e690a]
+
+https://github.com/sass/sass/commit/3d27be5d0c9cff02e48398d29997f0a99d558ef1
+
+これで良さそうなんだけれど、
+
+ gem 'sass', :git => 'git://github.com/sass/sass.git', :ref =>  '3d27be5d0c9cff02e48398d29997f0a99d558ef1'
+
+とすると、
+
+ Fetching git://github.com/sass/sass.git
+ fatal: Could not parse object '3d27be5d0c9cff02e48398d29997f0a99d558ef1'.
+ Git error: command `git reset --hard 3d27be5d0c9cff02e48398d29997f0a99d558ef1` in directory
+ /home/osamu/.rvm/gems/ruby-2.3.1@album/bundler/gems/sass-3d27be5d0c9c has failed.
+ If this error persists you could try removing the cache directory
+ '/home/osamu/.rvm/gems/ruby-2.3.1@album/cache/bundler/git/sass-d1bc97264a602a16cbc8b7962b139cf458860561'
+
+といって怒られてしまいます???
+
+** 試してみる [#m3274067]
+
+ bootstrap-carousel
+
+ div[ id="carousel-example-generic" class="carousel slide" data-ride="carousel"
+ data-interval="{ this.interval }" data-pause="{ this.pause }"
+ data-wrap="{ this.wrap }" data-keyboard="{ this.keyboard }" ]
+
+ / Indicators
+ ol class="carousel-indicators"
+ li[ each="{ this.items }" data-target="#carousel-example-generic"
+ data-slide-to="{ index }" class="{ active: index==0 }" ]
+
+ / Wrapper for slides
+ div class="carousel-inner"
+ div each="{ this.items }" class="{ item: true, active: index==0 }"
+ img src="{ src }" alt="{ caption }"
+ div class="carousel-caption"
+ h2
+ | { caption }
+
+ / Controls
+ a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"
+ span class="fa fa-angle-left"
+ a class="right carousel-control" href="#carousel-example-generic" data-slide="next"
+ span class="fa fa-angle-right"
+
+ sass:
+ .carousel-inner > .item
+ text-align: center
+
+ .carousel-inner > .item > img
+ display: inline
+
+ .carousel-inner .carousel-caption h2
+ color: rgba(0,0,0,0.6)
+ font-size: 40px
+ text-shadow: 0px 0px 5px rgba(255, 255, 255, 0.6), 0px 0px 10px rgba(255, 255, 255, 0.6)
+
+ .carousel-indicators li
+ background-color: rgba(0,0,0,0.4)
+ box-shadow: 0 0 5px rgba(0,0,0,0.6)
+ border-color: rgba(255,255,255,0.8)
+ margin-left: 6px
+ margin-right: 6px
+
+ .carousel-indicators li.active
+ border-color: rgba(255,255,255,0.8)
+ background-color: rgba(255,255,255,0.8)
+ margin-left: 6px
+ margin-right: 6px
+
+ img
+ opacity: 0.8
+
+ coffee:
+ @on 'update', ->
+ @interval = opts.interval ? 5000
+ @pause = opts.pause ? "hover"
+ @wrap = opts.wrap ? true
+ @keyboard = opts.keyboard ? true
+
+ @items = for img, i in $(@root._innerHTML) when img.tagName == 'IMG'
+ caption: img.alt
+ src: img.src
+ index: i
+
+こんな感じで、かなり良いのだけれど・・・style タグに scoped を付けられないのが痛すぎる???
+
+そうでもないか。sass の先頭に tag 名を書いて、他を全て & から始めれば同じことになりそう。
+
* 質問・コメント [#x0da6bd0]
#article_kcaptcha