기본 콘텐츠로 건너뛰기

Meteor로 진지하게 접근해 보는 Rapid Prototyping web application

일단 진지진지 열매 10개 먹고 시작하자.
1. 빠르게 만들고
2. 적게 코드를 쓰고
3. 시각적으로 보기 좋을 것

필요한 건 뭐?
1. 빠르게 만들 프레임 워크
2. 적게 코드를 쓸 수 있는 언어
3. 시각적인 뼈대를 받쳐줄 템플릿

내가 선택한 건?
1. Meteor
2. Coffeescript + Less
3. Twitter bootstrap

자 시작해볼까?

미리 설치해야할 것들
1. node.js + npm (http://nodejs.org/#download)
2. meteor (http://meteor.com/)
3. Coffeescript (npm install -g coffee-script)
4. jQuery plug-in (meteor add jquery)
5. less plug-in (meteor add less)
6. coffeescript plug-in (meteor add coffeescript)
7. bootstrap plug-in (meteor add bootstrap)

4,5,6은 meteor 용 plug-in들인데 매번 less나 coffeescript를 컴파일하지 않아도 클라이언트쪽에서 쓸 수 있다는 점이 엄청 편하다.
글 쓰는 도중 meteor 가 0.3.4로 업데이트 되면서 bootstrap지원이 추가되었다. 만세!

일단 meteor 가 기본으로 생성한 css와 javascript 를 삭제하고 less와 coffeescript 로 교체하자.

<프로젝트명>.coffee 파일은 이정도로 시작하자.


# make Posts into global variable
@Posts = new Meteor.Collection 'Posts'
# when client
if Meteor.is_client
$.extend Template.add,
events:
'click #add': ->
Posts.insert
subject: $('#subject').val()
context: $('#context').val()
createdTimestamp: Date.now()
$('#subject').val('')
$('#context').val('')
$.extend Template.list,
posts: ->
result = Posts.find {}, sort:createdTimestamp:-1, limit:10
if Meteor.is_server
Meteor.startup -> console.log 'started'

아주 심플하다. 심플하다 못해 화가 난다.
그럼 HTML을 작성해보자.

<head>
<title>tenMinuteBlog</title>
<link rel="shortcut icon" href="/img/favicon.ico">
</head>

<body>
<div class="container">
<h1>Posts</h1>
{{> list}}
</div>
</body>

<template name="list">
<div class="list">
<ul>
{{> add}}
{{#each posts}}
{{> item}}
{{/each}}
</ul>
</div>
</template>

<template name="item">
<li id="{{_id}}">
<i class="icon-chevron-right"/>
<span>{{subject}}</span>
<pre>{{context}}</pre>
</li>
</template>

<template name="add">
<li class="">
<div class="subject">
<input type="text" placeholder="Title here..." id="subject" class="span5"/> 
</div>
<div class="context">
<textarea id="context" class="span5"></textarea>
</div>
<p>
<a class="btn" id="add" href="#">
<i class="icon-pencil">
</i>
Add
</a>
</p>
</li>
</template>

구조가 좀 이상해보일 수도 있지만 이것도 참 외견과 기능에 비해 단순하다.
기능별로 템플릿을 나눴다.
list 가 있고 그 하위에 add (포스트 추가), 그리고 n개의 post 에 대해서 each로 반복하면서 item을 보여주는 구조.
그래서 구현도 add버튼 클릭과 list템플릿의 posts collection을 받아오는 식으로 구현했다.
CSS? 아니 LESS?
워낙에 Bootstrap이 좋아서 별로 할게 없다.

/* CSS declarations go here */
li {
  list-style-type:none;
}

일단 요정도만 하자.
command line 에서 meteor 를 입력하고 띄워서 본다.
bootstrap 적용으로 모바일에서도 데스크탑에서도 볼만한 화면이 나온다.

http://acidsound.github.com/tenMinuteBlog 에 프로젝트를 일단 생성.
이것도 autogenerate 로 날로 먹은 것 치곤 나쁘지 않다.

댓글

이 블로그의 인기 게시물

세상 간단한 https(+secured websocket): Caddy

nginx, apache2 같은 걸로 매번 certbot 연동을 통해 https 하는게 지겨워서 알아보니 Caddy라는게 있더라. 설치법은 강하게 크기 위해 알아서 해본다. # cat /etc/caddy/Caddyfile your.shitty.site:8123 {   proxy / localhost:9123 {     websocket     transparent   } } 이건 외부에서 8123으로 들어오는 걸 내부적으로 9123로 맞춰서 https 맞춰주는 reverse proxy. 만일 port를 생략하면 # cat /etc/caddy/Caddyfile your.shitty.site {   proxy / localhost:9123 {     websocket     transparent   } } 기본포트인 443으로 되어 https://your.shitty.site 로 접속이 된다. 요새 말썽이던 cloudflare 버리고 netlify domain이랑 caddy를 쓰니까 앓던 이가 빠진 느낌. 이 조합은 당분간 계속 써야겠다 싶다.

저지연 오디오 생성 LLVC 사용기

https://github.com/KoeAI/LLVC 써봄 CUDA 11.8 버전 쓰고 있어 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 VC 없어서 설치 https://wikidocs.net/168848 참조 FAIRSEQ 관련 오류 https://github.com/facebookresearch/fairseq/issues/2908 pip install editdistance  설치 No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8' 오류 멀쩡하게 있는데 안됨. pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 torchaudio==2.1.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 다시 설치 set DISTUTILS_USE_SDK=1 이게 문젠가 설정하고 재도전 Using cached ruamel.yaml.clib-0.2.8-cp311-cp311-win_amd64.whl (118 kB) Building wheels for collected packages: fairseq   Building wheel for fairseq (pyproject.toml) ... error   error: subprocess-exited-with-error   × Building wheel for fairseq (pyproject.toml) did not run successfully.   │ exit code: 1   ╰─> [1829 lines of output]       No CUDA runtime is found, usi...