smalruby-editor 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca2760262a800ae93179d68b1880d57f112c11e1
4
- data.tar.gz: d06ed6ea197417608bc105a62eb51d7fd93398a6
3
+ metadata.gz: cb16d8aecfe041f7828d1eb715235f0ce8cc79e9
4
+ data.tar.gz: 6b6a21336c99739958984d7c0220fbaa3a211754
5
5
  SHA512:
6
- metadata.gz: 452e8be3795c6dd12feb1428c8d81d6dd2d4514af99a4658dda2428761c170d58d4ca4c78d6c56843207936a37567cfff7c26f606471492dcc6e3023560b88cc
7
- data.tar.gz: 5f8126ae92a0ccce0216007deedb91fd48eb4c31739f9f9fc0e006d616b14f55677aa53d09766fd33a2b4f092709df4c507c7da7d4cea3828f2d317ad8d40a41
6
+ metadata.gz: f6f20cea2500aad412b097b4f5bef82481f34fdf49aee63ff7c1b9279350408d7ecb9af83a3362f3e4c15bdfdeecfb3f9dd7b251a76a797e2c999345aa4b3807
7
+ data.tar.gz: c6aef9c719d5498d2bd10b64248b6485793fb73fe2114b4a040da07d295511234c88dacb753644e7304b740f6d930ca5f5b826d99b673423d6572a025bc2b21f
@@ -4,3 +4,48 @@
4
4
  category = 'pen'
5
5
  color = 160
6
6
  %>
7
+
8
+ # ペンを下ろす
9
+ # ペンを上げる
10
+ # <%
11
+ [
12
+ ['down_pen', 'ペンを下ろす'],
13
+ ['up_pen', 'ペンを上げる'],
14
+ ].each do |suffix, label|
15
+ n = "#{category}_#{suffix}"
16
+ %>
17
+
18
+ Blockly.Blocks['<%= n %>'] =
19
+ init: ()->
20
+ @setHelpUrl('')
21
+ @setColour(<%= color %>)
22
+ @appendDummyInput()
23
+ .appendField('<%= label %>')
24
+ @setPreviousStatement(true)
25
+ @setNextStatement(true)
26
+ @setTooltip('')
27
+
28
+ Blockly.Ruby['<%= n %>'] = (block) ->
29
+ Blockly.Ruby.characterMethodCall_('<%= suffix %>')
30
+ <% end %>
31
+
32
+ # ペンの色を[カラー]にする
33
+ <% n = "#{category}_set_pen_color" %>
34
+ Blockly.Blocks['<%= n %>'] =
35
+ init: ()->
36
+ @setHelpUrl('')
37
+ @setColour(<%= color %>)
38
+ @appendDummyInput()
39
+ .appendField('ペンの色を')
40
+ .appendField(new Blockly.FieldColour('#ff0000'), 'COLOUR')
41
+ .appendField('にする')
42
+ @setPreviousStatement(true)
43
+ @setNextStatement(true)
44
+ @setTooltip('')
45
+
46
+ Blockly.Ruby['<%= n %>'] = (block) ->
47
+ c = @getFieldValue('COLOUR')
48
+ red = parseInt(c[1..2], 16)
49
+ green = parseInt(c[3..4], 16)
50
+ blue = parseInt(c[5..6], 16)
51
+ Blockly.Ruby.characterSetVariable_('pen_color', "[#{red}, #{green}, #{blue}]")
@@ -21,7 +21,7 @@ Smalruby.SourceCode = Backbone.Model.extend
21
21
  if window.blockMode
22
22
  data = Blockly.Ruby.workspaceToCode()
23
23
  else
24
- data =window.textEditor.getSession().getDocument().getValue()
24
+ data = window.textEditor.getSession().getDocument().getValue()
25
25
 
26
26
  @set('data', data)
27
27
 
@@ -2,6 +2,7 @@
2
2
  Smalruby.LoadModalView = Backbone.View.extend
3
3
  events:
4
4
  'click #load-modal-ok-button': 'onOk'
5
+ 'click #load-modal-remix-button': 'onRemix'
5
6
 
6
7
  initialize: ->
7
8
  @$el.find('#load-modal-find-from-computer').click (e) =>
@@ -11,6 +12,7 @@ Smalruby.LoadModalView = Backbone.View.extend
11
12
  render: ->
12
13
  @type = null
13
14
  @program = null
15
+ @setRemix(false)
14
16
  @unselect()
15
17
 
16
18
  elLocalPrograms = @$el.find('#load-modal-local-programs')
@@ -60,6 +62,7 @@ Smalruby.LoadModalView = Backbone.View.extend
60
62
  data:
61
63
  source_code:
62
64
  filename: @program.filename
65
+ remix: @remix
63
66
  dataType: 'json'
64
67
  success: (data, textStatus, jqXHR) ->
65
68
  Smalruby.Views.MainMenuView.load(data.source_code)
@@ -71,6 +74,7 @@ Smalruby.LoadModalView = Backbone.View.extend
71
74
  data:
72
75
  source_code:
73
76
  filename: @program.filename
77
+ remix: @remix
74
78
  dataType: 'json'
75
79
  success: (data, textStatus, jqXHR) ->
76
80
  Smalruby.Views.MainMenuView.load(data.source_code)
@@ -80,6 +84,18 @@ Smalruby.LoadModalView = Backbone.View.extend
80
84
 
81
85
  @$el.modal('hide')
82
86
 
87
+ onRemix: ->
88
+ @setRemix(!@remix)
89
+
90
+ setRemix: (remix) ->
91
+ @remix = remix
92
+ e = $('#load-modal-remix-button')
93
+ buttonClass = 'btn-success'
94
+ if @remix
95
+ e.addClass(buttonClass)
96
+ else
97
+ e.removeClass(buttonClass)
98
+
83
99
  onLocalProgramClick: (e, program) ->
84
100
  @select(e.currentTarget, 'local', program)
85
101
 
@@ -28,6 +28,7 @@
28
28
  225
29
29
  264
30
30
  296
31
+ 160
31
32
  33
32
33
  43
33
34
  43
@@ -88,7 +88,7 @@ class SourceCodesController < ApplicationController
88
88
  program_path = local_program_paths.find { |path|
89
89
  rb_basename(path) == filename
90
90
  }
91
- load_local_file(program_path)
91
+ load_local_file(program_path, source_code_params[:remix])
92
92
  end
93
93
 
94
94
  def load_demo
@@ -96,7 +96,7 @@ class SourceCodesController < ApplicationController
96
96
  program_path = demo_program_paths.find { |path|
97
97
  rb_basename(path) == filename
98
98
  }
99
- load_local_file(program_path)
99
+ load_local_file(program_path, source_code_params[:remix])
100
100
  end
101
101
 
102
102
  def run
@@ -124,7 +124,7 @@ class SourceCodesController < ApplicationController
124
124
  private
125
125
 
126
126
  def source_code_params
127
- params.require(:source_code).permit(:data, :filename)
127
+ params.require(:source_code).permit(:data, :filename, :remix)
128
128
  end
129
129
 
130
130
  def get_file_info(file)
@@ -194,10 +194,16 @@ class SourceCodesController < ApplicationController
194
194
  path
195
195
  end
196
196
 
197
- def load_local_file(path)
197
+ def load_local_file(path, remix)
198
198
  if path
199
+ if remix == 'true'
200
+ filename = SourceCode.make_remix_filename("~/#{session[:username]}",
201
+ path.basename.to_s)
202
+ else
203
+ filename = path.basename.to_s
204
+ end
199
205
  info = {
200
- filename: path.basename.to_s,
206
+ filename: filename,
201
207
  type: MIME.check(path.to_s).try(:content_type) || 'text/plain',
202
208
  data: NKF.nkf('-w', path.read),
203
209
  size: path.size,
@@ -16,6 +16,26 @@ class SourceCode < ActiveRecord::Base
16
16
  validate :validate_filename
17
17
  validates :data, presence: true, allow_blank: true
18
18
 
19
+ MAX_REMIX_COUNT = 1000
20
+
21
+ # リミックス用のファイル名を生成する
22
+ def self.make_remix_filename(home_dir, filename)
23
+ home_dir = Pathname(home_dir).expand_path
24
+ filename = filename.dup
25
+ ext = filename.slice!(/\.rb(\.xml)?$/)
26
+ filename.slice!(/(_remix(\d+)?)+$/)
27
+ basename = "#{filename}_remix"
28
+ MAX_REMIX_COUNT.times do |i|
29
+ suffix = (i == 0 ? '' : sprintf('%02d', i + 1))
30
+ remix_name = "#{basename}#{suffix}"
31
+ if !home_dir.join("#{remix_name}.rb").exist? &&
32
+ !home_dir.join("#{remix_name}.rb.xml").exist?
33
+ return "#{remix_name}#{ext}"
34
+ end
35
+ end
36
+ fail "reach max remix count...: #{filename}"
37
+ end
38
+
19
39
  # シンタックスをチェックする
20
40
  def check_syntax
21
41
  _, stderr_str, status = *open3_capture3_ruby_c
@@ -27,6 +27,10 @@
27
27
  Computer
28
28
 
29
29
  .modal-footer
30
+ .pull-left
31
+ %button#load-modal-remix-button.btn<
32
+ %i.icon-refresh
33
+ リミックス
30
34
  %button.btn{:"data-dismiss" => "modal", :"aria-hidden" => "true"}<
31
35
  %i.icon-remove
32
36
  やめる
@@ -134,6 +134,17 @@
134
134
  -# 変数:ボリューム
135
135
  -#%block{:type => "#{category}_volume"}
136
136
 
137
+ - category = 'pen'
138
+ %category{:name => 'ペン'}
139
+ -# ペンを下ろす
140
+ %block{:type => "#{category}_down_pen"}
141
+
142
+ -# ペンを上げる
143
+ %block{:type => "#{category}_up_pen"}
144
+
145
+ -# ペンの色を[カラー]にする
146
+ %block{:type => "#{category}_set_pen_color"}
147
+
137
148
  - category = 'events'
138
149
  %category{:name => '~のとき'}
139
150
  -# まずは
@@ -1,3 +1,3 @@
1
1
  module SmalrubyEditor
2
- VERSION = '0.1.14'
2
+ VERSION = '0.1.15'
3
3
  end
@@ -68,7 +68,7 @@ Gem::Specification.new do |spec|
68
68
  ['launchy'],
69
69
  ['mime-types', '~> 1.16'],
70
70
  ['haml-rails'],
71
- ['smalruby', '~> 0.0.22'],
71
+ ['smalruby', '~> 0.0.23'],
72
72
  ]
73
73
  runtime_dependencies << ['therubyracer'] unless is_windows
74
74
  runtime_dependencies.each do |args|
File without changes
File without changes
File without changes
@@ -13,6 +13,29 @@ describe SourceCode, 'Rubyのソースコードを表現するモデル' do
13
13
  end
14
14
  end
15
15
 
16
+ describe '.make_remix_filename', 'リミックス用のファイル名を生成する' do
17
+ subject {
18
+ home_dir = Rails.root.join('spec/fixtures/files')
19
+ SourceCode.make_remix_filename(home_dir.to_s, filename)
20
+ }
21
+
22
+ {
23
+ '01.rb' => '01_remix03.rb',
24
+ '01.rb.xml' => '01_remix03.rb.xml',
25
+ '01_remix.rb' => '01_remix03.rb',
26
+ '01_remix02.rb' => '01_remix03.rb',
27
+ '01_remix03.rb' => '01_remix03.rb',
28
+ '02.rb' => '02_remix.rb',
29
+ '02.rb.xml' => '02_remix.rb.xml',
30
+ }.each do |_filename, _expected|
31
+ describe _filename do
32
+ let(:filename) { _filename }
33
+
34
+ it { should eq(_expected) }
35
+ end
36
+ end
37
+ end
38
+
16
39
  describe '#check_syntax', 'シンタックスをチェックする' do
17
40
  let(:source_code) {
18
41
  SourceCode.new(data: data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - ~>
186
186
  - !ruby/object:Gem::Version
187
- version: 0.0.22
187
+ version: 0.0.23
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ~>
193
193
  - !ruby/object:Gem::Version
194
- version: 0.0.22
194
+ version: 0.0.23
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: therubyracer
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -554,6 +554,9 @@ files:
554
554
  - spec/controllers/source_codes_controller_spec.rb
555
555
  - spec/fixtures/files/01.rb
556
556
  - spec/fixtures/files/01.rb.xml
557
+ - spec/fixtures/files/01_remix.rb
558
+ - spec/fixtures/files/01_remix02.rb
559
+ - spec/fixtures/files/01_remix10.rb.xml
557
560
  - spec/fixtures/files/favicon.ico
558
561
  - spec/helpers/editor_helper_spec.rb
559
562
  - spec/helpers/sessions_helper_spec.rb
@@ -598,10 +601,10 @@ files:
598
601
  - vendor/assets/javascripts/blockly/msg/js/ja.js
599
602
  - vendor/assets/javascripts/jquery.blockUI.js
600
603
  - vendor/assets/stylesheets/.keep
601
- - public/assets/application-53d651da3309caa498cc0ca6616dbead.css
602
- - public/assets/application-53d651da3309caa498cc0ca6616dbead.css.gz
603
- - public/assets/application-d60babdd5a50329b329487cf793c2e29.js
604
- - public/assets/application-d60babdd5a50329b329487cf793c2e29.js.gz
604
+ - public/assets/application-51ab300acd1779bfba20b099e7000b7e.css
605
+ - public/assets/application-51ab300acd1779bfba20b099e7000b7e.css.gz
606
+ - public/assets/application-dc485e2270d6c5fce20c149d1e2c4f8d.js
607
+ - public/assets/application-dc485e2270d6c5fce20c149d1e2c4f8d.js.gz
605
608
  - public/assets/favicon-a37c90b368fd8ed436cb8f9e9396465c.ico
606
609
  - public/assets/jquery-ui/animated-overlay-c48c87b7a95316f4698484e3b85ee4aa.gif
607
610
  - public/assets/jquery-ui/ui-bg_flat_0_aaaaaa_40x100-58b63faadd031ca3db096dfdffd90224.png
@@ -730,6 +733,9 @@ test_files:
730
733
  - spec/controllers/source_codes_controller_spec.rb
731
734
  - spec/fixtures/files/01.rb
732
735
  - spec/fixtures/files/01.rb.xml
736
+ - spec/fixtures/files/01_remix.rb
737
+ - spec/fixtures/files/01_remix02.rb
738
+ - spec/fixtures/files/01_remix10.rb.xml
733
739
  - spec/fixtures/files/favicon.ico
734
740
  - spec/helpers/editor_helper_spec.rb
735
741
  - spec/helpers/sessions_helper_spec.rb