Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Typescript template generation #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Configurations:
Typescript::Rails::Compiler.default_options = [ ... ]
```

To use typescript template generator, add to your config file:

```
config.app_generators.javascript_engine :typescript
```

## Contributing

Expand Down
13 changes: 13 additions & 0 deletions lib/rails/generators/typescript/assets/assets_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "rails/generators/named_base"

module Typescript
module Generators
class AssetsGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)

def copy_coffee
template "javascript.ts", File.join('app/assets/javascripts', class_path, "#{file_name}.ts")
end
end
end
end
Empty file.
7 changes: 5 additions & 2 deletions lib/typescript/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails/engine'

class Typescript::Rails::Engine < Rails::Engine
# For now, let's not be the default generator ...
# config.app_generators.javascript_engine :ts
# config.app_generators.javascript_engine :typescript

if config.respond_to?(:annotations)
config.annotations.register_extensions("ts") { |annotation| /#\s*(#{annotation}):?\s*(.*)$/ }
end
end
15 changes: 15 additions & 0 deletions test/asset_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'test_helper'
require 'rails/generators/typescript/assets/assets_generator'

class AssetGeneratorTest < Rails::Generators::TestCase
tests Typescript::Generators::AssetsGenerator

destination File.expand_path("../tmp", __FILE__)
setup :prepare_destination

def test_assets
run_generator %w(posts)
assert_no_file "app/assets/javascripts/posts.js"
assert_file "app/assets/javascripts/posts.ts"
end
end
19 changes: 19 additions & 0 deletions test/controller_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'test_helper'
require 'rails/generators/rails/controller/controller_generator'
require 'rails/generators/typescript/assets/assets_generator'

class ControllerGeneratorTest < Rails::Generators::TestCase
tests Rails::Generators::ControllerGenerator

destination File.expand_path("../tmp", __FILE__)
setup do
prepare_destination
copy_routes
end

def test_assets
run_generator %w(posts --javascript-engine=typescript --orm=false)
assert_no_file "app/assets/javascripts/posts.js"
assert_file "app/assets/javascripts/posts.ts"
end
end
19 changes: 19 additions & 0 deletions test/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'test_helper'
require 'rails/generators/rails/scaffold/scaffold_generator'
require 'rails/generators/typescript/assets/assets_generator'

class ScaffoldGeneratorTest < Rails::Generators::TestCase
tests Rails::Generators::ScaffoldGenerator

destination File.expand_path("../tmp", __FILE__)
setup do
prepare_destination
copy_routes
end

def test_assets
run_generator %w(posts --javascript-engine=typescript --orm=false)
assert_no_file "app/assets/javascripts/posts.js"
assert_file "app/assets/javascripts/posts.ts"
end
end
Empty file added test/support/routes.rb
Empty file.