chunky_projects 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  [package]
2
- name = "chunky_projects"
2
+ name = "internal"
3
3
  version = "0.0.0"
4
4
  edition = "2021"
5
5
  authors = ["Zach Ahn <engineering@zachahn.com>"]
@@ -11,3 +11,4 @@ crate-type = ["cdylib"]
11
11
 
12
12
  [dependencies]
13
13
  magnus = { version = "0.6.2" }
14
+ rustextile = "1"
@@ -3,4 +3,4 @@
3
3
  require "mkmf"
4
4
  require "rb_sys/mkmf"
5
5
 
6
- create_rust_makefile("chunky_projects/chunky_projects")
6
+ create_rust_makefile("chunky_projects/internal")
@@ -1,12 +1,17 @@
1
- use magnus::{function, prelude::*, Error, Ruby};
1
+ use magnus::{class, function, prelude::*, Error, Ruby};
2
+ use rustextile::{HtmlKind, Textile};
2
3
 
3
- fn hello(subject: String) -> String {
4
- format!("Hello from Rust, {subject}!")
4
+ fn to_html(textile: String) -> String {
5
+ let parser = Textile::default().set_html_kind(HtmlKind::HTML5);
6
+ let html = parser.parse(textile.as_str());
7
+
8
+ return html;
5
9
  }
6
10
 
7
11
  #[magnus::init]
8
12
  fn init(ruby: &Ruby) -> Result<(), Error> {
9
- let module = ruby.define_module("ChunkyProjects")?;
10
- module.define_singleton_method("hello", function!(hello, 1))?;
13
+ let namespace = ruby.define_module("ChunkyProjects")?;
14
+ let internal = namespace.define_class("Internal", class::object())?;
15
+ internal.define_singleton_method("to_html", function!(to_html, 1))?;
11
16
  Ok(())
12
17
  }
@@ -0,0 +1,7 @@
1
+ module ChunkyProjects
2
+ class Error < StandardError
3
+ end
4
+
5
+ class EncodingError < Error
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module ChunkyProjects
2
+ def self.to_html(textile)
3
+ if textile.encoding.name != "UTF-8"
4
+ raise ChunkyProjects::EncodingError, "Textile encoding must be UTF-8"
5
+ end
6
+ if !textile.valid_encoding?
7
+ raise ChunkyProjects::EncodingError, "Textile encoding must be valid UTF-8"
8
+ end
9
+
10
+ Internal.to_html(textile)
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChunkyProjects
4
- VERSION = "0.0.0"
4
+ VERSION = "0.0.1"
5
5
  end
@@ -1,9 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module ChunkyProjects
4
+ end
5
+
6
+ require_relative "chunky_projects/error"
3
7
  require_relative "chunky_projects/version"
4
- require_relative "chunky_projects/chunky_projects"
8
+ require_relative "chunky_projects/public"
5
9
 
6
- module ChunkyProjects
7
- class Error < StandardError; end
8
- # Your code goes here...
10
+ begin
11
+ ruby_version = RUBY_VERSION[/^\d+\.\d+/]
12
+ require_relative "chunky_projects/#{ruby_version}/internal"
13
+ rescue LoadError
14
+ require "chunky_projects/internal"
9
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_projects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
@@ -25,6 +25,8 @@ files:
25
25
  - ext/chunky_projects/extconf.rb
26
26
  - ext/chunky_projects/src/lib.rs
27
27
  - lib/chunky_projects.rb
28
+ - lib/chunky_projects/error.rb
29
+ - lib/chunky_projects/public.rb
28
30
  - lib/chunky_projects/version.rb
29
31
  homepage: https://github.com/zachahn/chunky_projects
30
32
  licenses: