履歴: プログラミング/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/12 9:36:40) → 比較: プログラミング/Riot.js/riot_js-railsの手直し (2016/10/20 14:32:50)
@@ -1,17 +1,34 @@
[[公開メモ]]
-#contents
-
* 概要 [#ha9b50ed]
rails から riot.js を使うための gem として、
[[riot_js-rails>https://github.com/bjarosze/riot_js-rails]] というのがあるのですが、
環境によってどうもうまく動かないように思えたため、手直しできないか調べてみました。
+最終的に、rails 3.1 から 5.0.0.1 までのすべてで動きそうな状況までこぎ着けました。
+
「[[それっぽい記事を発見>#l4374caa]]」に原因が、「[[やってみる>#la58b64f]]」 以下に回答らしきものがあります。
+この成果をまとめた gem が、https://github.com/osamutake/riot_js-rails こちらにあります。~
+現在、この稿の内容を riot_js-rails の本家へプルリクエストの形で投げ、回答待ちの状況です。
+
+本家に取り込まれるまでの間は Gemfile 中で、
+
+ LANG:ruby
+ gem 'riot_js-rails', :git => 'git://github.com/osamutake/riot_js-rails',
+ :branch => 'support_sprockets_2_3_and_4'
+
+とすれば使えます。
+
+* 目次 [#vb58b525]
+
+#contents
+
* 症状 [#ofe19cd3]
+rails 4.0.13 ではうまく動きませんでした。
+
LANG:console
$ ruby --version
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
@@ -97,6 +114,8 @@
* Rails のバージョンを上げると [#a1c9dd34]
+rails 4.2.6 では動きました。
+
LANG:console
$ rvm use ruby-2.2.1
$ ruby --version
@@ -268,7 +287,7 @@
後者で読まれた v4.1.1 でも変更されていないにも関わらず、
同じことをしてみても、どうもうまくいかず、困ってしまいます。
-* coffee-rails のまねをする [#c2ace7e8]
+** coffee-rails のまねをする [#c2ace7e8]
$ git clone https://github.com/rails/coffee-rails.git
$ mv coffee-rails/ riottag-rails
@@ -316,7 +335,7 @@
さらに、ものすごく重要なことがさらっと書いてあった。
->prockets 4 will not chain asset extensions so .coffee.erb is explicitly registered in addition to .coffee. If your application introduces a new mime/extension combo it will be responsible for registering all combinations.
+>Sprockets 4 will not chain asset extensions so .coffee.erb is explicitly registered in addition to .coffee. If your application introduces a new mime/extension combo it will be responsible for registering all combinations.
Sprockets 4 ではさらに大幅な変更が来るみたいですね。
@@ -435,7 +454,7 @@
でクリアできるとのこと。
-これがないとまったく始まらない(汗
+上でにっちもさっちもいかなかったのはこれのせい(汗
で、下記コードはかなり良い線行っている気がします。
@@ -607,7 +626,7 @@
|2.2.1|4.2.0|3.7.0|ok||
|2.3.1|5.0.0.1|3.7.0|ok||
-テストは下記のように行った。
+テストは下記のスクリプトで行った。
通常の .tag ファイルが正しく読み込めるかどうかと、
haml を使った .tag.haml ファイルが正しく読み込めるかどうかをテストしている。
@@ -618,252 +637,270 @@
と表示される。
-*** sprockets 2.2.3 / 2.0.5 のテストスクリプト [#e11ce618]
+** テストスクリプト [#zc561111]
- LANG:sh
- #!/bin/sh
- rvm use 1.9.3-p551
- rvm gemset create riot-test
- rvm use 1.9.3-p551@riot-test
- gem uninstall --all --force
- gem install rails -N -v 3.2.11
- rails new riot-test
- cd riot-test
- rm public/index.html
- echo "\
- RiotTest::Application.routes.draw do
- root :to => 'main#index'
- end
- " >config/routes.rb
- rails g controller main index
- # rails s # to test sprockets works well
- echo "
- gem 'therubyracer', platforms: :ruby
- gem 'haml-rails'
- gem 'riot_js-rails', path: 'path/to/riot_js-rails'
- " >>Gemfile
- bundle install
- mkdir app/assets/javascripts/riot-tags
- echo "\
- <test>
- <div><test> tag is working.</div>
- </test>
- " >app/assets/javascripts/riot-tags/test.js.tag
- echo '
- %haml-test
- %div
- &="<haml-test> tag is working."
- ' >app/assets/javascripts/riot-tags/haml-test.js.tag.haml
- echo '
- <test data-riot></test>
- <haml-test data-riot></haml-test>
- ' >app/views/main/index.html.erb
- echo "\
- //= require jquery
- //= require jquery_ujs
- //= require riot
- //= require riot_rails
- //= require_tree .
- " >app/assets/javascripts/application.js
- grep sprockets Gemfile.lock
- rails s
+Gist に上げた。
+
+https://gist.github.com/osamutake/0ccbdf96a5ac70a36ebce38db0a33137
+
+** github に上げた [#x63554b5]
+
+上記コードを組み入れた riot_js-rails を github に上げました。
+
+https://github.com/osamutake/riot_js-rails
+
+** プルリクエストを書いてみた [#i044a1a0]
+
+作法をよく知らないので、失礼がないと良いのだけれど。
+
+https://github.com/bjarosze/riot_js-rails/pull/18
+
+本家に取り込まれるまでの間は Gemfile 中で、
+
+ LANG:ruby
+ gem 'riot_js-rails', :git => 'git://github.com/osamutake/riot_js-rails',
+ :branch => 'support_sprockets_2_3_and_4'
+
+とすれば上記コードを使えます。
+
+* さらに手直し [#afdb6fc3]
+
+** テストを phantomjs で書いてみる [#g282f17e]
+
+phantomjs の導入は、バイナリをとってくればすぐできる。
+
+http://phantomjs.org/download.html を見て、
+
+ LANG:console
+ $ wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
+ $ cd /usr/local/src
+ $ sudo tar fxj ~/phantomjs-2.1.1-linux-x86_64.tar.bz2
+ $ sudo ln -s /usr/local/src/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
+ $ phantomjs -v
+ 2.1.1
+
+あ、npm でも良いみたいですね。こっちの方が簡単だ。
+
+ $ npm install phantomjs-prebuilt
+ $ ~/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs --version
+ 2.1.1
+
+あとは、
+
+test.js
+ LANG:js
+ (function(){
+ var page = require("webpage").create();
+ page.viewportSize = {width: 1024, height: 768};
+
+ 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);
+ }
+ });
+
+ })();
-後始末は
+などというスクリプトを用意して、
- LANG:sh
- #!/bin/sh
- cd ..
- rm -r riot-test
- rvm gemset delete riot-test
+ $ 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
-rails 3.1.12 = sprockets 2.0.5 も、上記の 3.2.11 を 3.1.12 とするだけで動いた。
+ if defined?(::Slim)
+ Processor.register_nested(app, config, 'slim', :html, ::Slim::Template)
+ end
+ end
+のようにして登録したところ、slim も使えるようになった。
-*** sprockets 2.12.4 のテストスクリプト: [#c777ace6]
+rails 4 では(?) slim-rails を導入していれば何もしなくても slim がつかえるようだったが、
+上記コードにより slim-rails を Gemfile に含める必要はなく、slim のみでよくなる。
- LANG:sh
- #!/bin/sh
- rvm use 1.9.3
- rvm gemset create riot-test
- rvm use 1.9.3@riot-test
- gem uninstall --all --force
- gem install rails -N -v 4.0.0
- rails new riot-test
- cd riot-test
- echo "\
- RiotTest::Application.routes.draw do
- root :to => 'main#index'
- end
- " >config/routes.rb
- rails g controller main index
- # rails s # to test sprockets works well
- echo "
- source 'https://rubygems.org'
- gem 'rails', '4.0.0'
- gem 'sqlite3'
- gem 'sass-rails', '~> 4.0.0'
- gem 'coffee-rails', '~> 4.0.0'
- gem 'jquery-rails'
- gem 'therubyracer', platforms: :ruby
- gem 'haml-rails'
- gem 'riot_js-rails', path: 'path/to/riot_js-rails'
- " >Gemfile
- bundle install
- mkdir app/assets/javascripts/riot-tags
- echo "\
- <test>
- <div><test> tag is working.</div>
- </test>
- " >app/assets/javascripts/riot-tags/test.js.tag
- echo '
- %haml-test
- %div
- &="<haml-test> tag is working."
- ' >app/assets/javascripts/riot-tags/haml-test.js.tag.haml
- echo '
- <test data-riot></test>
- <haml-test data-riot></haml-test>
- ' >app/views/main/index.html.erb
- echo "\
- //= require jquery
- //= require jquery_ujs
- //= require riot
- //= require riot_rails
- //= require_tree .
- " >app/assets/javascripts/application.js
- grep sprockets Gemfile.lock
- rails s
+* slim + coffeescript + sass + riot の使い勝手 [#yfd84c69]
-rails 4.1.16 = sprockets 2.12.4 も同様にして動いた。
+** 属性の引用符 [#v88d605f]
-このとき Gemfile は、
+riot で属性を javascript で与える場合、引用符を省略して次のように書けますが、
- LANG:sh
- #!/bin/sh
- echo "
- source 'https://rubygems.org'
- gem 'rails', '4.1.16'
- gem 'sqlite3'
- gem 'sass-rails', '~> 4.0.3'
- gem 'coffee-rails', '~> 4.0.0'
- gem 'jquery-rails'
- gem 'therubyracer', platforms: :ruby
- gem 'haml-rails'
- gem 'riot_js-rails', path: 'path/to/riot_js-rails'
- " >Gemfile
+ LANG: html
+ <li each={ item, i in items }>{ item }</li>
-とし、rails g controller main index の前に Gemfile を書き換えないと
-spring が邪魔をして正しく controller を作成できなかった~
-(恐らく spring にバージョン指定が必要)
+slim で
-*** sprockets 3.7.0 (rails 4.2) のテストスクリプト: [#c777ace6]
+ LANG: slim
+ li each={ item, i in items }
+ | { item }
- LANG:sh
- #!/bin/sh
- rvm use 2.2.1
- rvm gemset create riot-test
- rvm use 2.2.1@riot-test
- gem uninstall --all --force
- gem install rails -N -v 4.2
- rails _4.2.0_ new riot-test
- cd riot-test
- echo "\
- RiotTest::Application.routes.draw do
- root :to => 'main#index'
- end
- " >config/routes.rb
- rails g controller main index
- # rails s # to test sprockets works well
- echo "
- source 'https://rubygems.org'
- gem 'rails', '4.2.0'
- gem 'sqlite3'
- gem 'sass-rails', '~> 5.0'
- gem 'coffee-rails', '~> 4.1.0'
- gem 'jquery-rails'
- gem 'therubyracer', platforms: :ruby
- gem 'haml-rails'
- gem 'riot_js-rails', path: 'path/to/riot_js-rails'
- " >Gemfile
- bundle install
- mkdir app/assets/javascripts/riot-tags
- echo "\
- <test>
- <div><test> tag is working.</div>
- </test>
- " >app/assets/javascripts/riot-tags/test.tag
- echo '
- %haml-test
- %div
- &="<haml-test> tag is working."
- ' >app/assets/javascripts/riot-tags/haml-test.tag.haml
- echo '
- <test data-riot></test>
- <haml-test data-riot></haml-test>
- ' >app/views/main/index.html.erb
- echo "\
- //= require jquery
- //= require jquery_ujs
- //= require riot
- //= require riot_rails
- //= require_tree .
- " >app/assets/javascripts/application.js
- grep sprockets Gemfile.lock
- rails s
+と書くと属性値の { } の中を ruby で解釈しようとしてエラーになってしまいます。
-*** sprockets 3.7.0 (rails 5.0.0.1) のテストスクリプト [#u426f453]
+属性値は必ず引用符で囲まなければなりません。
- LANG:sh
- #!/bin/sh
- rvm use 2.3.1
- rvm gemset create riot-test
- rvm use 2.3.1@riot-test
- gem uninstall --all --force
- gem install rails -N -v 5.0.0.1
- rails _5.0.0.1_ new riot-test
- cd riot-test
- echo "\
- RiotTest::Application.routes.draw do
- root :to => 'main#index'
- end
- " >config/routes.rb
- rails g controller main index
- # rails s # to test sprockets works well
- echo "
- source 'https://rubygems.org'
- gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
- gem 'sqlite3'
- gem 'sass-rails', '~> 5.0'
- gem 'coffee-rails', '~> 4.2'
- gem 'jquery-rails'
- gem 'listen', '~> 3.0.5'
- gem 'therubyracer', platforms: :ruby
- gem 'haml-rails'
- gem 'riot_js-rails', path: 'path/to/riot_js-rails'
- " >Gemfile
- bundle install
- mkdir app/assets/javascripts/riot-tags
- echo "\
- <test>
- <div><test> tag is working.</div>
- </test>
- " >app/assets/javascripts/riot-tags/test.tag
- echo '
- %haml-test
- %div
- &="<haml-test> tag is working."
- ' >app/assets/javascripts/riot-tags/haml-test.tag.haml
- echo '
- <test data-riot></test>
- <haml-test data-riot></haml-test>
- ' >app/views/main/index.html.erb
- echo "\
- //= require jquery
- //= require jquery_ujs
- //= require riot
- //= require riot_rails
- //= require_tree .
- " >app/assets/javascripts/application.js
- grep sprockets Gemfile.lock
- rails s
+ 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
+