module SmalrubyEditor
Constants
- COLORS
ジャンルのカラー
- DATABASE_YML_TEMPLATE
- VERSION
Public Class Methods
create_home_directory(home_dir = nil)
click to toggle source
# File lib/smalruby_editor.rb, line 51 def create_home_directory(home_dir = nil) if home_dir.blank? path = ENV['SMALRUBY_EDITOR_HOME'] || '~/.smalruby-editor' home_dir = Pathname(path).expand_path end create_under_home_directories(home_dir) create_database_yml(home_dir) create_config_yml(home_dir) home_dir end
home_directory()
click to toggle source
return smalruby's home directory (default is '~/.smalruby-editor').
# File lib/smalruby_editor.rb, line 45 def home_directory path = ENV['SMALRUBY_EDITOR_HOME'] || '~/.smalruby-editor' Pathname(path).expand_path end
hsv_to_rgb(h, s, v)
click to toggle source
c4se.hatenablog.com/entry/2013/08/04/190937 をほぼコピーした
# File lib/smalruby_editor.rb, line 21 def hsv_to_rgb(h, s, v) s /= 100.0 v /= 100.0 c = v * s x = c * (1 - ((h / 60.0) % 2 - 1).abs) m = v - c r, g, b = *( case when h < 60 then [c, x, 0] when h < 120 then [x, c, 0] when h < 180 then [0, c, x] when h < 240 then [0, x, c] when h < 300 then [x, 0, c] else [c, 0, x] end ) [r, g, b].map { |channel| sprintf('%02x', ((channel + m) * 255).ceil) }.join end
osx?()
click to toggle source
Mac OS Xかどうかを返す
# File lib/smalruby_editor.rb, line 76 def osx? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_OSX_MODE'] || File.exist?(Rails.root.join('tmp', 'osx'))) true else /darwin/ =~ RbConfig::CONFIG['arch'] end end
raspberrypi?()
click to toggle source
Raspberry Piかどうかを返す
# File lib/smalruby_editor.rb, line 64 def raspberrypi? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_RASPBERRYPI_MODE'] || File.exist?(Rails.root.join('tmp', 'raspberrypi'))) true else RbConfig::CONFIG['arch'] == 'armv6l-linux-eabihf' end end
windows?()
click to toggle source
Windowsかどうかを返す
# File lib/smalruby_editor.rb, line 88 def windows? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_WINDOWS_MODE'] || File.exist?(Rails.root.join('tmp', 'windows'))) true else /windows|mingw|cygwin/i.match(RbConfig::CONFIG['arch']) end end
Private Class Methods
create_config_yml(home_dir)
click to toggle source
# File lib/smalruby_editor.rb, line 128 def create_config_yml(home_dir) config_yml_path = home_dir.join("config", "config.yml") unless config_yml_path.exist? File.open(config_yml_path, "w") do |f| toolbox_name__preference_names = Preference.make_toolbox_name_to_preference_names_hash Preference.toolbox_names.each do |toolbox_name| f.puts("#toolbox_name: #{toolbox_name}") preference_names = toolbox_name__preference_names.delete(toolbox_name) puts_preference_names(f, preference_names) f.puts end preference_names_list = toolbox_name__preference_names.values + [Preference.general_preference_names, Preference.admin_preference_names] preference_names_list.each do |preference_names| puts_preference_names(f, preference_names) f.puts end end end end
create_database_yml(home_dir)
click to toggle source
# File lib/smalruby_editor.rb, line 120 def create_database_yml(home_dir) database_yml_path = home_dir.join('config', 'database.yml') db_path = home_dir.join('db', 'standalone.sqlite3') File.open(database_yml_path, 'w') do |f| f.write(DATABASE_YML_TEMPLATE.gsub(/%db_path%/, db_path.to_s)) end end
create_under_home_directories(home_dir)
click to toggle source
# File lib/smalruby_editor.rb, line 102 def create_under_home_directories(home_dir) dirs = %w(log db config tmp/cache tmp/pids tmp/sessions tmp/sockets).map { |s| home_dir.join(s) } dirs.each do |dir| FileUtils.mkdir_p(dir) end end
puts_preference_names(io, preference_names)
click to toggle source
# File lib/smalruby_editor.rb, line 153 def puts_preference_names(io, preference_names) preference_names.try(:each) do |preference_name| case preference_name when Preference::BOOLEAN_FIELD_REGEXP io.puts("##{preference_name}: true") else io.puts(%{##{preference_name}: ""}) end end end
Private Instance Methods
create_home_directory(home_dir = nil)
click to toggle source
# File lib/smalruby_editor.rb, line 51 def create_home_directory(home_dir = nil) if home_dir.blank? path = ENV['SMALRUBY_EDITOR_HOME'] || '~/.smalruby-editor' home_dir = Pathname(path).expand_path end create_under_home_directories(home_dir) create_database_yml(home_dir) create_config_yml(home_dir) home_dir end
home_directory()
click to toggle source
return smalruby's home directory (default is '~/.smalruby-editor').
# File lib/smalruby_editor.rb, line 45 def home_directory path = ENV['SMALRUBY_EDITOR_HOME'] || '~/.smalruby-editor' Pathname(path).expand_path end
hsv_to_rgb(h, s, v)
click to toggle source
c4se.hatenablog.com/entry/2013/08/04/190937 をほぼコピーした
# File lib/smalruby_editor.rb, line 21 def hsv_to_rgb(h, s, v) s /= 100.0 v /= 100.0 c = v * s x = c * (1 - ((h / 60.0) % 2 - 1).abs) m = v - c r, g, b = *( case when h < 60 then [c, x, 0] when h < 120 then [x, c, 0] when h < 180 then [0, c, x] when h < 240 then [0, x, c] when h < 300 then [x, 0, c] else [c, 0, x] end ) [r, g, b].map { |channel| sprintf('%02x', ((channel + m) * 255).ceil) }.join end
osx?()
click to toggle source
Mac OS Xかどうかを返す
# File lib/smalruby_editor.rb, line 76 def osx? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_OSX_MODE'] || File.exist?(Rails.root.join('tmp', 'osx'))) true else /darwin/ =~ RbConfig::CONFIG['arch'] end end
raspberrypi?()
click to toggle source
Raspberry Piかどうかを返す
# File lib/smalruby_editor.rb, line 64 def raspberrypi? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_RASPBERRYPI_MODE'] || File.exist?(Rails.root.join('tmp', 'raspberrypi'))) true else RbConfig::CONFIG['arch'] == 'armv6l-linux-eabihf' end end
windows?()
click to toggle source
Windowsかどうかを返す
# File lib/smalruby_editor.rb, line 88 def windows? if Rails.env != 'test' && (ENV['SMALRUBY_EDITOR_WINDOWS_MODE'] || File.exist?(Rails.root.join('tmp', 'windows'))) true else /windows|mingw|cygwin/i.match(RbConfig::CONFIG['arch']) end end