mirror of https://github.com/tildeio/helix
Add text_transform example
This commit is contained in:
parent
d09c796ea3
commit
bd225ddca9
|
@ -3,7 +3,7 @@ cache:
|
|||
- '%HOMEDRIVE%%HOMEPATH%\.multirust -> .appveyor.yml'
|
||||
|
||||
environment:
|
||||
EXAMPLES: duration calculator console membership turbo_blank
|
||||
EXAMPLES: duration calculator console membership text_transform turbo_blank
|
||||
VERBOSE: true
|
||||
RUST_BACKTRACE: 1
|
||||
matrix:
|
||||
|
|
|
@ -11,7 +11,7 @@ include = [
|
|||
|
||||
[workspace]
|
||||
|
||||
members = ["examples/calculator", "examples/console", "examples/duration", "examples/membership", "examples/turbo_blank"]
|
||||
members = ["examples/calculator", "examples/console", "examples/duration", "examples/membership", "examples/text_transform", "examples/turbo_blank"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.0"
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -3,7 +3,7 @@ task :test do
|
|||
sh "bundle exec rake"
|
||||
end
|
||||
|
||||
examples = ENV["EXAMPLES"] || "duration calculator console membership turbo_blank"
|
||||
examples = ENV["EXAMPLES"] || "duration calculator console membership text_transform turbo_blank"
|
||||
|
||||
sh "bash ./examples/runner default #{examples}"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "text_transform"
|
||||
version = "0.1.0"
|
||||
authors = ["Godfrey Chan <godfrey@tilde.io>"]
|
||||
|
||||
[lib]
|
||||
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies.helix_runtime]
|
||||
path = "../.."
|
|
@ -0,0 +1,5 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'helix_runtime', path: '../../ruby'
|
||||
gem 'rake', '~> 10.0'
|
||||
gem 'rspec', '~> 3.4'
|
|
@ -0,0 +1,37 @@
|
|||
PATH
|
||||
remote: ../../ruby
|
||||
specs:
|
||||
helix_runtime (0.5.0.alpha.2)
|
||||
rake (>= 10.0)
|
||||
thor (~> 0.19.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.3)
|
||||
rake (10.5.0)
|
||||
rspec (3.5.0)
|
||||
rspec-core (~> 3.5.0)
|
||||
rspec-expectations (~> 3.5.0)
|
||||
rspec-mocks (~> 3.5.0)
|
||||
rspec-core (3.5.4)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-expectations (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-mocks (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-support (3.5.0)
|
||||
thor (0.19.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
helix_runtime!
|
||||
rake (~> 10.0)
|
||||
rspec (~> 3.4)
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.4
|
|
@ -0,0 +1,27 @@
|
|||
require 'bundler/setup'
|
||||
require 'helix_runtime/build_task'
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
# For Windows
|
||||
$stdout.sync = true
|
||||
|
||||
HelixRuntime::BuildTask.new("text_transform") do |t|
|
||||
t.build_root = File.expand_path("../..", __dir__)
|
||||
t.helix_lib_dir = File.expand_path("../../ruby/windows_build", __dir__)
|
||||
t.pre_build = -> {
|
||||
Dir.chdir("../../ruby") do
|
||||
puts "\n\nBuilding helix runtime\n\n"
|
||||
Bundler.with_clean_env do
|
||||
sh "bundle exec rake compile:native"
|
||||
end
|
||||
puts "\nRuntime built\n\n"
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||
t.verbose = false
|
||||
end
|
||||
|
||||
task :spec => :build
|
||||
task :default => :spec
|
|
@ -0,0 +1,2 @@
|
|||
require 'helix_runtime'
|
||||
require 'text_transform/native'
|
|
@ -0,0 +1,2 @@
|
|||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
||||
require 'text_transform'
|
|
@ -0,0 +1,11 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe "TextTransform" do
|
||||
it "can widen text" do
|
||||
expect(TextTransform.widen("Hello Aaron (@tenderlove)!")).to eq("Hello Aaron (@tenderlove)!")
|
||||
end
|
||||
|
||||
it "can narrowen text" do
|
||||
expect(TextTransform.narrowen("Hello Aaron (@tenderlove)!")).to eq("Hello Aaron (@tenderlove)!")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
#[macro_use]
|
||||
extern crate helix_runtime;
|
||||
|
||||
declare_types! {
|
||||
class TextTransform {
|
||||
def widen(text: String) -> String {
|
||||
text.chars().map(|char| {
|
||||
match char {
|
||||
' ' => '\u{3000}', '!' => '!', '"' => '"', '#' => '#', '$' => '$', '%' => '%', '&' => '&', '\'' => ''',
|
||||
'(' => '(', ')' => ')', '*' => '*', '+' => '+', ',' => ',', '-' => '-', '.' => '.', '/' => '/',
|
||||
'0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7',
|
||||
'8' => '8', '9' => '9', ':' => ':', ';' => ';', '<' => '<', '=' => '=', '>' => '>', '?' => '?',
|
||||
'@' => '@', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G',
|
||||
'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
|
||||
'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', 'U' => 'U', 'V' => 'V', 'W' => 'W',
|
||||
'X' => 'X', 'Y' => 'Y', 'Z' => 'Z', '[' => '[', '\\' => '\', ']' => ']', '^' => '^', '_' => '_',
|
||||
'`' => '`', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g',
|
||||
'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o',
|
||||
'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w',
|
||||
'x' => 'x', 'y' => 'y', 'z' => 'z', '{' => '{', '|' => '|', '}' => '}', '~' => '~', _ => char,
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
def narrowen(text: String) -> String {
|
||||
text.chars().map(|char| {
|
||||
match char {
|
||||
'\u{3000}' => ' ', '!' => '!', '"' => '"', '#' => '#', '$' => '$', '%' => '%', '&' => '&', ''' => '\'',
|
||||
'(' => '(', ')' => ')', '*' => '*', '+' => '+', ',' => ',', '-' => '-', '.' => '.', '/' => '/',
|
||||
'0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7',
|
||||
'8' => '8', '9' => '9', ':' => ':', ';' => ';', '<' => '<', '=' => '=', '>' => '>', '?' => '?',
|
||||
'@' => '@', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E', 'F' => 'F', 'G' => 'G',
|
||||
'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
|
||||
'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T', 'U' => 'U', 'V' => 'V', 'W' => 'W',
|
||||
'X' => 'X', 'Y' => 'Y', 'Z' => 'Z', '[' => '[', '\' => '\\', ']' => ']', '^' => '^', '_' => '_',
|
||||
'`' => '`', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g',
|
||||
'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o',
|
||||
'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w',
|
||||
'x' => 'x', 'y' => 'y', 'z' => 'z', '{' => '{', '|' => '|', '}' => '}', '~' => '~', _ => char,
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue