0

In case of gem file, I can use javascript library after install gem file but I don't know how to use this library I found!

(Here is the link of the library in github) https://github.com/teampopong/hangul-jamo-js

This one describes how to use code. I used 'casperjs' library thorough installing. but this one is new for me...there is no gem file..

I'd like to use this library to split my korean string object in my javascript file!

=====================Edit============================================

I want to use hangul-jamo-js's method in my javascript file like this

this is one of my javascirpt file including casperjs code

//= require hangul-jamo.js

var a = HANGUL.toChosungs('강철');
***there is underline on HANGUL when I put this code***
var words = [];
var casper = require('casper').create();

. . And this is my application.html.erb head section

<title>Workspace</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <script src="https://raw.githubusercontent.com/teampopong/hangul-jamo-js/master/hangul-jamo.js"></script>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

I wrote all of code refer to answers below but In my javascript file, it said "HANGUL is not defined"...

but when I put all of hangul-jamo-js codes in my javascript file it defined...

How can I use this hangul-jamo-js codes in my javascript?? I have to run my code through this command

parkhk1757@wow:~/workspace/app/assets/javascripts $ casperjs myjavascript.js
2
  • can you put the name of the first Javascript file you posted? Is that myjavascript.js? Commented Sep 5, 2015 at 15:45
  • yes I'm writing code in myjavascript.js! Commented Sep 5, 2015 at 16:08

4 Answers 4

1

Original answer

The simplest solution is to put this:

<script src="https://raw.githubusercontent.com/teampopong/hangul-jamo-js/master/hangul-jamo.js"></script>

in the <head> section of the app/views/layouts/application.html.erb file. Then you can use the code with Hangul.startsWith..., etc.

Updated answer

Alright, it looks like you're confusing two different parts of your webapp.

application.html.erb

Your application.html.erb is hit via web request. You would need to fire up your rails server (e.g. bin/rails s) and go to localhost:3000 from your browser to load hangul-jamo.js and it would only be available to the javascript loaded on that page after that file. This doesn't sound like what you want.

casperjs

From what I understand (I haven't used it myself), casperjs is a command line program that you use to run a script file written in Javascript (in your case, myjavascripts.js). That script file is used to run tests against your webapp by loading the page using PhantomJS as if you were loading it in a browser. The Javascript files loaded in your webapp (e.g. hangul-jamo.js) are NOT available in your myjavascripts.js file.

Solution

To be able to use hangul-demo.js first note that capserjs uses the PhantomJS require, which means it uses CommonJS style modules. Here's an introduction to CommonJS modules. I've turned it into a CommonJS style module here. Put in the folder node_modules/ and use from myjavascripts.js like this:

var hangul = require('./hangul');
console.log(hangul.toJamos('hello'));
Sign up to request clarification or add additional context in comments.

1 Comment

Could you please read my question one more time I tried and edit my question!
1

In the web page header with

 <%= javascript_include_tag "route_to_your_js" %>

http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_include_tag

However if you want a specific page contribute to his layout page header, take a look in content_for

Comments

1

You may want to try putting the js file localy in your app/assets/javascript file and include it as a required asset in your application.js file

ie: //= require hangul-jamo.js

Comments

1

Include hangul-jamo.js files into..app/assets/javascripts folder and add reference in application.js like

include your files in your application.js file.

//= require yourjsfile.js

by default you will have

//= require_tree .

which requires all js files from assets/javascript path, so you don't have to type it on your own, but should place the file inside assets/javascript path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.