반응형
Organic Development

 

Link : http://net.tutsplus.com/tutorials/javascript-ajax/organic-development/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+nettuts+%28Nettuts%2B%29

 

Github : https://github.com/VarnaLab/node-organic

 

Core & addons

basic building blocks, improvements, experiments, addons and etc related to `core`

 

 

Introduction

I was working as a graphic designer a few years ago and a common problem that I would run into was picking color schemes for new projects. One of my colleagues said, “Just pick a nice photo and grab colors from there”. This technique works well because photos offer you a natural combination of colors. So I was thinking, “Why not transfer this same concept to my work as a coder?”. And this is where Organic comes in to play. When I was first introduced to Organic I was amazed how simple it was and at the same time, how flexible its approach is. Finally, I had something which encourages modular programming, its just as useful as the MVC pattern, and it’s a great tool for architecting.


The Concept

As you may have guessed, the Organic concept is biology based. Your main application acts as a Cell, which has a Membrane and a Nucleus. But the real job of a Cell is done by the Organelles, which communicate between each other with Chemicals. Of course, the elements and the processes in Organic are not 100% identical to real life Cells, but they are pretty close. Now, I know it sounds crazy, but once you start working with it you’ll see how simple and natural this approach can be when applying it to your apps.

organic-concept


Download Organic

Organic is distributed as a Node module. So you should have NodeJS already installed. If you don’t, please go to nodejs.org and grab the latest version for your OS. Your package.json file should look like this:

1
2
3
4
5
6
7
8
9
{
"name": "OrganicDevelopment",
"version": "0.0.0",
"description": "Organic development",
"dependencies": {
"organic": "0.0.11"
},
"author": "Your Name Here"
}

Run npm install in the same directory and the manager will download the necessary files. The core of Organic is actually pretty small. It contains only the definition of the main elements – Cell, Nucleus, Membrane, Plasma, Organelle, Chemical, and DNA. Of course it comes with a few tests, but it’s a small package overall. This helps in making it easy to learn and start developing with almost immediately.


The Example

For this article I decided to create a simple web site using only the core of Organic. The source code can be downloaded at the top of this article, if you’d like to follow along. I think that this sample application is the best way to present this new pattern. The site contains two pages – Home and About. Here’s a screenshot of the site:

site

The app contains two buttons linking to the two different pages. The About page has just a little bit more text than the Home page does. Simple enough, but let’s see what’s behind the curtains. Here’s a diagram displaying the basic request flow of our application:

structure

The user sends a request to our NodeJs application. The Server accepts the request and sends it to the Router. After that, the Render knows which page should be used and returns an answer to the Server. At the end, the response is then sent to the user.

There is one additional element, Data Providers, which prepares the needed CSS or JavaScript for the Render (keep in mind that in our example app I didn’t use JavaScript, there is only a CSS module).

Here’s what our app would look like as a Cell, in Organic:

structureorganic

In the Cell, we have a membrane which keeps the internal elements away from the outside world. In this membrane is where we’ll put our first organel, our Server, because this is where data can either enter or leave our application. The other organelles (Router, Render, and CSS) are placed in the plasma. All of these modules are communicating between each other via chemicals (request, page and css, marked in red). The Server emits a request chemical. The Router emits a page and the CSS organel sends the css. I should also mention that the plasma acts as an event bus for the chemicals. Organelles listen for a particular chemical and if found, they react on it.

Here’s another request flow diagram, but this time with the chemicals that are emitted (marked in red):

structureorganic2

Now if this concept is still unclear to you, don’t worry, as we proceed through the next few sections and get into the actual code, it should make more sense then!


DNA

dna

Everything starts with the DNA (Deoxyribonucleic acid), which you can think of as a Cells configuration. In this DNA is where you will define your organelles and their settings.

Let’s create a new index.js file and put in the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var DNA = require("organic").DNA;
var Cell = require("organic").Cell;
var dna = new DNA({
membrane: {
Server: {
source: "membrane.Server"
}
},
plasma: {
Router: {
source: "plasma.Router"
},
CSS: {
source: "plasma.CSS",
file: "./css/styles.css"
},
Render: {
source: "plasma.Render",
templates: "./tpl/"
}
}
});
var cell = new Cell(dna);

The above code is just a definition for the DNA and Cell initialization. You can see we’ve placed our Server in the membrane and the Router, CSS, and Render in the plasma, as we discussed in the last section. The source property is actually mandatory and contains the path to your individual organelles.

Keep in mind that the file property in the CSS organel and the templates property in the Render organel are actually custom properties, which I set. You can add whatever customization you need in here as well.

And just for your reference, the directory structure for your app should look like this:

1
2
3
4
5
6
7
8
9
10
/css
/styles.css
/membrane
/Server.js
/node_modules
/plasma
/CSS.js
/Render.js
/Router.js
/tpl

A Basic Organel

1
2
3
4
5
6
7
8
9
10
var Chemical = require("organic").Chemical;
var Organel = require("organic").Organel;
var util = require("util");
module.exports = function YourOrganelName(plasma, config) {
Organel.call(this, plasma);
// your custom logic here
}
util.inherits(module.exports, Organel);

The above code shows the basic format for creating an organel. If you want to use this.emit or this.on you’ll need to make sure to inherit Organel as we did above. And actually, the plasma parameter variable has those exact same methods (emit and on), so you could use plasma directly and skip the inheritance if you wanted.

Also, notice the config parameter; This is the object that you defined in your DNA, which is a good place for any of your custom configuration.


The Server

The Server is your main organel, which accepts requests and sends responses to the browser. Here’s what your Server organel should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var port = 3000;
module.exports = function Server(plasma, config) {
Organel.call(this, plasma);
var self = this;
http.createServer(function(req, res) {
console.log("request " + req.url);
self.emit(new Chemical({
type: "request",
req: req
}), function(html) {
res.writeHead(200);
res.end(html);
});
}).listen(port, '127.0.0.1');
console.log('Server running at http://127.0.0.1:' + port + '/');
}

Two things are happening here. The first one is the definition of the NodeJS server, which of course has a handler accepting request (req) and response (res) objects. Once the request is received, the Server organel sends a chemical, with the type request, notifying the rest of the organelles. It also attaches the req object, so whoever needs more information about the incoming request can access data from the chemical directly.

The emit method then takes a second argument which is a callback function. You can use this to return the flow back to the organel, which sends the chemical. I.e. once the Render finishes its job, it calls the Server’s callback. It takes the produced HTML and by using the res object sends the page to the user.


The Router

For our next organel, the Router just listens for a request chemical, which is sent by the Server. It gets the URL from the req object and decides which page should be shown. Here’s the code for the Router:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = function Router(plasma, config) {
Organel.call(this, plasma);
var self = this;
this.on("request", function(chemical, sender, callback) {
var page = chemical.req.url.substr(1, chemical.req.url.length);
page = page == "" || page == "/" ? "home" : page;
self.emit(new Chemical({
type: "page",
page: page,
ready: callback
}));
});
}

Now, the router itself just emits a new chemical with a type of page. Keep in mind, there are two other organels listening for this chemical as well, but by default, it’s not transfered to all of the other elements in the plasma. Of course, there may be times when you will need such functionality. To do so, you just need to return false; in the chemical’s listener. We’ll see this in action in the next section.


CSS Styles Provider

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module.exports = function CSS(plasma, config) {
Organel.call(this, plasma);
var cssStyles = fs.readFileSync(config.file).toString();
var self = this;
this.on("page", function(chemical) {
self.emit(new Chemical({
type: "css",
value: cssStyles
}));
return false;
});
}

This module is just a simple one-task organel which gets the path to the .css file, reads it, and later emits a chemical containing the actual CSS styles. Also, pay attention to the return false; statement at the bottom. As I said from the last section, it’s important to do this, otherwise the Render will not receive the page chemical sent by the Router. This happens because the CSS organel is defined before the Render in the DNA.


The Render

And lastly, here’s the code for our Render organel:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = function Render(plasma, config) {
Organel.call(this, plasma);
var getTemplate = function(file, callback) {
return fs.readFileSync(config.templates + file);
}
var formatTemplate = function(html, templateVars) {
for(var name in templateVars) {
html = html.replace("{" + name + "}", templateVars[name]);
}
return html;
}
var templates = {
layout: getTemplate("layout.html").toString(),
home: getTemplate("home.html").toString(),
about: getTemplate("about.html").toString(),
notFound: getTemplate("notFound.html").toString()
}
var vars = {};
var self = this;
this.on("css", function(chemical) {
vars.css = chemical.value;
});
this.on("page", function(chemical) {
console.log("Opening " + chemical.page + " page.");
var html = templates[chemical.page] ? templates[chemical.page] : templates.notFound;
html = formatTemplate(templates.layout, {content: html});
html = formatTemplate(html, vars);
chemical.ready(html);
});
}

There are two helper methods here: getTemplate and formatTemplate which implement a simple template engine for loading an external HTML file and replacing mustache-style variables. All of the templates are stored in an object for quick access. Afterwards we have just a few lines for HTML formatting and then everything is ready to go. The Render organel also listens for the css chemical and lastly the application provides a notFound 404 page, if needed.

So here’s what the final app’s directory structure looks like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/css
/styles.css
/membrane
/Server.js
/node_modules
/plasma
/CSS.js
/Render.js
/Router.js
/tpl
/about.html
/home.html
/layout.html
/notFound.html

Running the Application

Simply run node index.js in the console and you should see something similar to this:

console1

With your server running, you should now be able to visit http://127.0.0.1:3000 in your favorite browser. Try clicking on the links to switch between the two pages a few times and then go back to your console to view the output.

console2

You should see a nice report about the applications recent activity. Now you may also notice something else in the console:

1
2
request /favicon.ico
Opening favicon.ico page.

You can see that there is one more request coming from the browser. It wants to load favicon.ico. However our little site doesn’t have such an icon, so it just opens the 404 page. You can try this for yourself by visiting: http://127.0.0.1:3000/favicon.ico.

If you’d like to check out the full source code for this tutorial, you can download it using the download link at the top of this page.

반응형
반응형

How To Remove Unnecessary Modules in jQuery

http://www.hongkiat.com/blog/jquery-remove-modules/

 

OS X 에서 jquery 설치시 불필요한 모듈 제외하고 설치하기.

 

jQuery is undoubtedly the most popular JavaScript library, (almost) every website on this planet is using it. This affects jQuery to include all the functionalities within the library to cover every instance and possibility.

However, when we work on a simple website, we might only use a few of the functions. Thus, it would be more efficient if we were able to run only that necessary function and not everything other unused function as well. As of version 1.8, jQuery allows us to do this. We are able to exclude some jQuery modules that are not necessary in your project. So, let’s see how we can do it.

First thing first

First, we need to install some tools required to do the job. These tools are Git, Grunt, and Node.js. If you running on OS X, the easiest way to install all these tools is through an OS X Package Manager called Homebrew.

Install Homebrew

So, let’s open up your Terminal and run the following command to install Homebrew. As said, Homebrew will let us install the other mentioned tools more easily.

  1. ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Install Git

After the Homebrew installation completed, run the following command to install Git.

  1. brew install git

Install Node.js

Run the following line to install Node.js

  1. brew install node

Install Grunt

Lastly, we need to install Grunt. Run this command.

  1. npm install -g grunt-cli

Build jQuery

Currently, jQuery allows the following modules to be excluded.

Modules Command Description
Ajax -ajax This specifies the jQuery AJAX API that includes jQuery.ajax(). jQuery.get(), and .load() function
CSS -css This specifies the functions from jQuery CSS Category that includes .addClass(), .css(), and .hasClass().
Deprecated -deprecated This specifies the deprecated modules or functions.
Event Alias -event-alias This specifies the event functions like .click(), .focus(), and .hover().
Dimensions -dimensions This specifies the functions to set CSS dimension. Such functions include .height(), .innerHeight(), and .innerWidth().
Effects -effects This specifes the functions that set animation effects, such as .slideToggle(), .animate() and .fadeIn()
Offset -offset This specifies the functions that retrieve45 coordinates and position. Such funtions include .offset() and .position().

Before we are able to customize the jQuery, we need to clone it from the Github repo by running this command in the Terminal.

  1. git clone git://github.com/jquery/jquery.git

You should then find a new folder named jquery created under your user folder. Navigate to that directory using this command.

  1. cd jquery

Next, we need to install Node dependencies modules to run our project.

  1. npm install

We then build our jQuery by simply running Grunt command (and hit enter)

  1. grunt

It will return the following report, if the operation succeeds.

And as we can see from the report, our jQuery is saved within the dist/ folder. Our jQuery is, at this point, set with all the functionalities, thus the size is quite large, 239kb. The minified version is at 83kb.

Removing Modules

Let’s say, we want to remove the Effect modules from jQuery; we can run this command.

  1. grunt custom:-effects

If we take a look back at the file size, it is now decreased to 220 kb.

To exclude multiple modules, separate each module with a comma, for example:

  1. grunt custom:-effects,-ajax,-deprecated

Final Thought

jQuery can help us manipulate DOM easily, but with 200 kb more at the size, it could affect your website performance. So, by eliminating some unnecessary jQuery modules, your jQuery script will certainly run faster and more efficient. We hope that this little tip would be useful for your next project.

반응형
반응형

Bacon.js

A small functional reactive programming lib for JavaScript.

Link : https://github.com/raimohanska/bacon.js

Turns your event spaghetti into clean and declarative feng shui bacon, by switching from imperative to functional. It's like replacing nested for-loops with functional programming concepts like map and filter. Stop working on individual events and work with event streams instead. Transform your data with map andfilter. Combine your data with merge and combine. Then switch to the heavier weapons and wieldflatMap and combineTemplate like a boss.

It's the _ of Events. Too bad the symbol ~ is not allowed in Javascript.

Here's the stuff.

You can also check out my entertaining (LOL), interactive, solid-ass slideshow.

And remember to give me feedback on the bacon! Let me know if you've used it. Tell me how it worked for you. What's missing? What's wrong? Please contribute!

 

반응형
반응형

A JavaScript standard library based on the Ruby core-lib

RubyJS is a JavaScript implementation of all methods from Ruby classes like Array, String, Numbers, Time and more.

 

http://rubyjs.org/

 

 

100% JavaScript

RubyJS is built on top of JavaScript. It runs in all browsers. No additional tools needed.

Works like Ruby

Easily port code from Ruby to JavaScript. Become productive in JavaScript in hours. Fully tested with rubyspec.

Fast and small

20 kilobytes minified and gzipped. It is as fast or faster than comparable libraries.


Utility belt or OO

Use RubyJS like a utility belt, transforming arrays, string and continue with native objects. Or use the fully-fledged RubyJS objects and make use of their mutator (aka bang) methods.

All-in-one Library

String, Array, Time, Numbers, Range, and more. RubyJS gives you the power of multiple 3rd party libraries, with one coherent API. So you only have to learn, manage and update one.

Ruby Features

Block arguments, destructive (bang-) methods, duck-typing, special variables, mixins.

 

 

Getting Started with RubyJS

 :   http://rubyjs.org/getting-started.html

 

 

반응형
반응형

Flippant.js — A tiny library for flipping things over

 

http://labs.mintchaos.com/flippant.js/

 

 

반응형
반응형

cujoJS — Build modular, maintainable web apps

cujojs

Homepage: http://cujojs.com/
GitHub: https://github.com/cujojs
Twitter: http://twitter.com/cujojs

 

 

cujojs's Repositorieshttps://github.com/cujojs/repositories

 

 

RESTful HTTP client for JavaScript

 : https://github.com/cujojs/rest 

반응형
반응형
Javascript library 추가하기  - APTANA

 

link : https://wiki.appcelerator.org/display/tis/JavaScript+Library+Support

 

JavaScript Library Support

메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동
Chapters

Libraries

Studio ships with the ability for users to extend support for JavaScript libraries in content assist. Below is a list of libraries and content assist files we've located that should be compatible with Studio. This is not a complete list, and compatibility is not guaranteed, but if you see something on this list and it doesn't work, please let us know.

Dojo (http://dojotoolkit.org)

The XML files Dojo ships require a little bit of massaging to be readable by the Studio content assist processor.

Drop the SDOCML file anywhere into your Web Project (feel free to put it in a special folder).

Alternately, to update docs to a newer version (should one come out)

ExtJS/Sencha (http://extjs.com)

Drop the SDOCML file anywhere into your Web Project (feel free to put it in a special folder).

Google

Drop the VSDoc files into your Web Project.

jQuery (http://jquery.org)

Install the jQuery ruble and reference it:

  1. Commands > Install Bundle > jQuery
  2. Right click on a project, select Properties > Project Build Path and select the checkbox for jQuery 1.6.2.

If you already have the jQuery bundle:

  1. Choose Commands > Bundle Development > Update User Bundles

or

  1. Find the Aptana Rubles folder on your system
  2. Delete the Ruble
  3. Restart Studio
  4. Install the Ruble again as above

OpenLayers (http://openlayers.org/)

There is a current bug with adding the single http://www.openlayers.org/api/OpenLayers.js file to a project to get content assist. As a workaround:

Note that this technique will not actually show documentation on the classes. For that, we need a SDOCML file which could be created from the source Natural Docs.

YUI (http://developer.yahoo.com/yui/)

Drop the SDOCML file into your Web Project.

반응형
반응형

Jindo

 

http://dev.naver.com/projects/jindo

 

Jindo는 NHN에서 제작한 Javascript Library 이다. 사내의 Javascript Application 제작시에 반복적으로 발생하는 로직을 컴포넌트화 하여 결과물의 품질을 향상시키기 위한 목적으로 작성되었다.


 


 


 


 

아래 그림과 같이 Jindo는 desktop에서 사용하는 프레임워크와 컴포넌트, 모바일에서 지원하는 프레임워크와 컴포넌트로 구성되어 있다.
캡처_2.PNG


 

레퍼런스

Jindo

- Jindo Jindo Mobile
한국어 버전 [http]API Reference [http]API Reference
영어 버전 [http]API Reference [http]API Reference

Jindo Component


Jindo Mobile Component


지원 브라우저



Desktop Mobile
msie.sm.png
(6.0 이상)
android.png
(2.1 ~ 4.1)
chrome.sm.png
(2 이상)
ios.png
(3.0 ~ 6.x)
webkit.sm.png
(4.0 이상)
-
gecko.sm.png
(3.0 이상)
-
presto.sm.png
(10.0 이상)
-

지원도구

Jindo 사용시 유용한 도구를 지원하고 있다.

현재 지원도구에는 진도추출기와 진도업데이터가 있으며 지속적으로 개선 및 추가할 예정이다.

진도추출기

  • 서비스 코드에서 사용하는 Jindo 만을 추출해서 서비스에 최적화된 custom Jindo 파일을 생성한다.
  • 파일 크기가 줄어들고 불필요한 스크립트가 실행되지 않기 때문에 로딩성능에 향상을 가져올 수 있다.
  • 진도추출기가이드

진도업데이터

  • Jindo 를 사용 중인 서비스에서 Jindo Library 를 업그레이드 할 때 주의해야 할 변경사항을 엑셀보고서로 출력해준다.
  • Jindo Library 업그레이드에 대한 막연한 불안감을 해소하고 비용을 절감해 줄 수 있다.
  • 진도업데이터가이드
반응형

+ Recent posts