본문 바로가기
개발/dart

5. Install Shared Packages

by 허허 그림 2014. 3. 2.
728x90

* 전체 링크

1.get started

2. Connect Dart & HTML

3. Add Elements to the DOM

4, Remove DOM Elements

- 5. Install Shared Packages

6. Define a Custom Element

7. Use Future-Based APIS

8. Use Streams for Data

9. Fetch Data Dynamically

10. Get Input from a Form

11. Use Indexed DB

12. Write Command-line Apps


Install Shared Packages
공유 패키지 설치하기

Borrow and share code.
코드빌려주고 공유하기.

Now that you’re able to create and run a Dart application and have a basic understanding of DOM programming, you are ready to leverage code written by other programmers. Many interesting and useful packages of reusable Dart code are available at the pub.dartlang.org repository.

이제 당신은 DOM 프로그래밍의 Dart 어플리케이션을 제작할수 있고 실행시킬 수 있습니다.그리고 이제 DOM 프로그래밍의 기본적인 지식도 가지게 되었습니다. 당신은 다른 프로그래머에 의해 작성된 영향력 있는 코드를 사용할 준비가 되었습니다. 흥미롭고 유용한 재사용할 수 있는 많은 Dart 코드를 pub.dartlang.org 저장소에서 이용 가능 합니다.

This tutorial shows you how to use pub—a package manager that comes with Dart—to install one of the packages in the repository, the vector_math package. You can follow these same steps to install any package hosted at pub.dartlang.org; just change the package name when you get to that step. This tutorial also describes some of the resources you can expect to find in a well-built package.

이번 튜토리얼에서는 저장소에 있는 패키지중에 하나(vector_math 패키지)를 인스톨 하기 위해 pub(Dart에 있는 패키지 매니저)를 어떻게 사용하는지 설명하겠습니다. 당신은 pub.dartlang.org에 있는 어떠한 패키지를 설치하기 위해 다음에 나오는 절차를 따라하면 됩니다. 그리고 당신이 이 단계를 거쳐 패키지를 설치하고 나면 패키지 이름을 변경하기만 하면 됩니다. 이번 튜토리얼은 또한 당신이 잘 만들어진 패키지를 찾을 수 있도록 하는 방법을 설명해 줄 것입니다.

About the pubspec.yaml file
pubspec.yaml 파일에 대해

To use an external package, your application must itself be a package. Any application with a valid pubspec.yaml file in its top-level directory is a package and can therefore use external packages. When you create an application using Dart Editor, Dart Editor automatically creates a pubspec.yaml file.

외부 패키지를 이용하기 위해서, 당신의 애플리케이션은 반드시 패키지가 되어야 합니다. l제일 상단 디렉토리에 있는 유효한 pubspec.yaml이 있는 어떠한 어플리케이션도 팩키지이고 외부 패키지도 이용할 수 있습니다. 당신이 Dart 에디터를 사용해서 어플리케이션을 만들때 Dart 에디터는 자동으로 pubspec.yaml 파일을 생성합니다.

Start Dart Editor and create a new application with the name vector_victor. Double click pubspec.yaml to view its contents.

Dart 에디터를 시작하고 vector_victor 이라고 하는 새로운 어플리케이션을 만드세요. 그리고 그 안에 있는 pubspec.yaml 파일을 더블 클릭하세요.

The pubspec.yaml file contains the package specification written in YAML (visit Pubspec Format for in-depth coverage). Dart Editor provides a user interface for editing the pubspec.yaml file so that you don’t have to worry about the YAML format. Or you can click the Source tab at the bottom of the Editor pane to edit the YAML code directly. Below is the pubspec.yaml file that was created for the vector_victor application.

pubspec.yaml 파일은 YAML(좀 더 자세한 내용을 알고 싶으면 Pubspec Fortmat를 방문하세요)로 작성된 팩키지 사양이 있습니다. Dart 에디터는 pubspec.yaml 파일을 편집하기 위해서 사용자 인터페이스를 제공하기 때문에 YAML 형식에 대해서는 걱정할 필요가 없습니다. 또는 당신은 YAML  코드를 직접 편집하기를 원한다면 에디터 창의 맨 아래에 있는 Source 탭을 클릭할 수도 있습니다. 아래에는 vector_victor 어플리케이션을 만들때 생성된 pubspec.yaml 파일이 있습니다.

The package name is required. You’ll note that the pubspec.yaml file already lists a dependency on the browser package. Web applications that don’t use Polymer need the browser package.

팩키지 이름은 필수 입니다. 당신은 pubspec.yaml 파일이 벌써 브라우저 패키지에 대한 종속성이 열거 되어 있다는 것을 알 수 있습니다. Polymer을 사용하지 않는 웹 어플리케이션은 브라우저 패키지가 필요합니다.

Name the package dependencies
패키지 종속서 이름 짓기

To use an external library package, you need to add the package to your application’s list of dependencies in the pubspec.yaml file. Each item in the dependencies list specifies the name, and sometimes the version, of a package that your application uses.

외부 라이브러리 패키지를 이용하기 위해서는, 당신은 pubspec.yaml 파일에 당신의 어플리케이션의 종속성 리스트에 패키지를 추가하는 것이 필요합니다. 종속성 리스트에 있는 각 아이템들은 당신의 어플리케이션이 사용할 패키지의 이름과 때로는 버전을지정합니다.

Let’s make the vector_victor application have a dependency on the vector_math package, which is available at pub.dartlang.org.

vector_victor 어플리케이션이 pub.dartlang.org에서 사용가능한 vector_math 패키지에 대해 의존성을 가지도록 만들어봅시다.

  • Click the Add button in Dart Editor.

  • Dart 에디터에서 Add 버튼을 클릭하세요.

  • Enter the name of the package in the popup window.

  • 팝업 윈도우에서 패키지의 이름을 입력하세요.

Dart Editor adds the package name to the list.

Dart 에디터는 리스트에서 패키지의 이름을 추가합니다.

Notice the Version field. any means that this application can use any version of the vector_math package. You could instead specify a particular version of the package. When versioning becomes important to your project, check out Pub’s Versioning Philosophy .

Version 필드를 한번 확인해 보세요. any라는 뜻은 이 프로그램(vector_victor)이 vector_math 패키지의 어떤 버전이라도 사용할 수 있다는 뜻입니다. 가지고 올려고 하는 패키지의 버전이 당신의 프로젝트에 중요할때는 패키지의 특정 버전을 지정할수도 있습니다. Pub의 버전 매기는 철학(?)에 대해 알고 싶으시다면 클릭

Here’s the new pubspec.yaml file:

여기에 새로운 pubspec.yaml 파일이 있습니다.

pub.dartlang.org is the primary public repository for Dart packages. pub automatically checks that website when resolving package dependencies. To use one of the packages from that site, you can specify it by its simple name, as we have done here.

pub.dartlang.org 은 Dart 패키지를 위한 중요한 공식 저장소 입니다.  pub 은 패키지 종속성을 해결하기 위해서 웹 사이트를 자동적으로 체크합니다. 해당 웹 사이트에서 패키지중에 하나를 이용하기 위해서 , 우리가 여기에서 금방 했던것 처럼, 당신은 그것의 간단한 이름을 지정할 수 있습니다.

Install the package dependencies
패키지 종속성 설치하기.

In Dart Editor, save pubspec.yaml with File > Save. When you save the file, Dart Editor automatically runs pub get, which recursively installs the Dart libraries from the packages in the dependencies list. You can also select Pub Install from the Tools menu in Dart Editor.

Dart 에디터에서 , File > Save를 사용해서 pubspec.yaml  파일을 저장하세요. 파일이 저장될때 Dart 에디터는 자동적으로 pub get 을 실행합니다. pub get 은 종속성리스트에 있는 패키지를 Dart 라이브러리에 재귀적으로 설치합니다. 또한 당신은 Dart 에디터의 Tools 메뉴에서 Pub Install을 선택할 수 있습니다. (현재  Dart 에디터 1.1.3에서는 Pub Install 메뉴를 찾을 수가 없네요..)

Pub puts the libraries in a directory called packages under the application’s top-level directory. Click the wee arrow to expand the packages directory. There you will find the vector_math directory, which links to the Dart libraries from the vector_math package.

Pub는 어플리케이션의 최상위 디렉토리 밑에 있는 packages 라고 하는 디렉토리 안에 라이브러를 추가합니다. 패키지 디텍토리를 펼치기 위해서는 그 옆에 있는 작은 화살표를 클릭하세요. 거기에서 당신은 vector_math 패키지에서 Dart 라이브러리와 관련이 있는       vector_math 디렉토리를 찾을 수 있을 것입니다.

Pub install works recursively; if the included package has dependencies, those packages are installed as well.

Pub 설치는 재귀적으로 작동합니다. 포함된 패키지가 종속성이 있는 경우에, 해당 패키지들은 함께 설치가 됩니다.

Pub install creates a file called pubspec.lock, which identifies the specific versions of the packages that were installed. This helps to provide a stable development environment. Later you can modify the version constraints and use pub update to update to new versions as needed.

Pub 설치는 설치되어져 있는 패키지의 특정 버전을 식별하는  pubspec.lock 이라고 하는 파일을 생성합니다. 이것은 안정적인 개발 환경을 제공하도록 합니다. 나중에 당신은 그 설치된 패키지  버전의 제약 조건을 수정할 수도 있고 필요에 따라서는 새로운 버전을 업데이트하기 위해서 pub update 을 사용할 수 있습니다.

What did you get (and not get)?
무엇을 얻고 얻을 수 없나?

Besides the Dart libraries, the vector_math package has other resources that might be useful to you that do not get installed into your application directory. Let’s take a step back for a moment to look at what you got and where it came from.

Dart 라이브러리 외에, vector_math 패키지는 당신의 어플리케이션의 디렉토리에 설치 되지 않았지만 당신에게 유용하게 쓰일 수 있는 다른 자원들을 가지고 있습니다. 당신이 설치한 것과 그것들이 어디에서 왔는지를 살펴보기 위해 다시 조금전의 뒤를 살펴보자.

To see the contents of the vector_math package, visit the Dart vector math repository  at github. Although many files and directories are in the repository, only one, lib, was installed when you ran pub get.

vector_math 패키지의 내용을 보기 위해서, Dart vector math repository를 방문하세요.저장소에 가보면 많은 파일과 디렉토리들이 있지만, pub get을 실행시켜서 설치된것은 단 하나 lib 입니다.


Dart libraries: The lib directory contains one or more Dart libraries, which can be imported into your Dart programs.

Dart 라이브러리: lib 디렉토리는 당신의 Dart 프로그램에 가져올 수 있는 하나 또는 다수의 Dart 라이브러리를 가지고 있습니다.


Housekeeping files: When using a package written by someone else, the README file is a good place to start. It should contain important information about the package, such as its intent, contents, samples, and instructions. The LICENSE file provides copyright and rules-of-use information. These files can be found at the package repository. They are not installed when you install a package.

관리용 파일들: 다른 사람들에 의해 만들어진 패키지를 사용할때, README 파일은 시작할때 읽어보는 것이 좋다. 그것은 패키지에 관한 중요한 정보를 가지고 있기 때문이다.예를 들면, 패키지의 의도, 내용, 예제 그리고 사용법등의 정보가 들어있다. LICENSE 파일은 저작권과 사용 규칙에 대한 정보를 제공합니다. 이러한 파일들은 패키지 저장소에서 찾아 볼수 있습니다. 이것들은 패키지를 설치할때 같이 설치 되지 않습니다.



Other resources: Along with Dart libraries, a package might also contain other resources such as example code, tests, scripts, and documentation. If a package contains these resources, they should be in the directories as specified in the pub conventions.

다른 자원들:  Dart 라이브러리와 함께, 패키지는 또한 예제 코드, 테스트, 스크립트와 문서등과 같은 다른 자원들을 가지고 있습니다. 패키지가 이런 자원들을 가지고 있다면 그것들은 pub 관습에 따른 디렉토리 안에 있어야 합니다.


Import libraries from a package
패키지로 부터 라이브러리 가져오기

Open the vector_math directory by clicking the little arrow.

작은 화살표를 클릭해서 vector_math 디렉토리를 여세요.

The directory contains a Dart file called vector_math.dart, which you import into your Dart application, and a src directory, which contains the source code for the library. As with the SDK libraries, use the import directive to use code from an installed library. The Dart SDK libraries are built-in and are identified with the special dart: prefix. For external libraries installed by pub, use the package: prefix.

이 디렉토리는 vector_math.dart 라고 하는 Dart 파일을 포함하고 있습니다. 그것은 당신의 Dart 어플리케이션에 가져온 것입니다. 그리고 src 디렉토리에는 vector_math 의 소스코드들이 있습니다. SDK 라이브러리와 마찬가지로, 설치된 라이브러리를 사용하기 위해서는 import 지시자를 사용하세요. Dart SDK 라이브러리는 내장되어 있고 특별한 dart:prefix로 식별되어 집니다. 설치된 외장 라이브러리를 사용하기 위해서는 package:prefix를 사용하세요.

import 'package:vector_math/vector_math.dart';

Note that you specify the filename, not the library name.

import 하여 가지고 올때 라이브러리 이름이 아니라 파일 이름을 적는다는 것을 기억하세요.

Other resources
다른 자원들.

  • Dart developers share packages at pub.dartlang.org. Look there for packages that might be useful to you, or share your own Dart packages. See the pub documentation to get started using and sharing packages.

  • Dart 개발자들은 pub.dartlang.org에 패키지를 공유합니다. 당신에 유용하게 쓰일 패키지를 여기서 찾아보세요. 또는 당신만의  Dart 패키지를 공유하세요. 패키지를 공유하고 사용하는 방법에 대해서 pub documentation을 보세요.

What next?

One package at pub.dartlang.org is Polymer.dart, which makes writing web applications easier with data binding, templates, and declarative event handlers. Check out the next tutorial, Define a Custom Element, for an introduction to Polymer.

pub.dartlang.org에 있는 패키지 중에 하나에는 Polymer.dart가 있습니다. 이것은 웹 응용프로그램의 데이터 바인딩, 템플릿화 그리고 선언적 이벤트 핸들러를 좀 더 쉡게 만들수 있도록 합니다. Polymer에서 소개하는 사용자 요소 정의하기인 다음번 튜토리얼을 체크하세요.


300x250

'개발 > dart' 카테고리의 다른 글

7. Use Future-Based APIs  (0) 2014.03.02
6. Defined a Custom Element  (0) 2014.03.02
4. Remove DOM Elements  (0) 2014.03.02
3. Add Elements to the DOM  (0) 2014.03.02
2. Connect Dart & HTML  (0) 2014.03.02

댓글