21
GEMS / PLUGINS Интересно, полезно, весело

RubyBarCamp “Полезные gems и plugins”

Embed Size (px)

DESCRIPTION

Слайды Гилберто Апостлиона

Citation preview

Page 1: RubyBarCamp “Полезные gems и plugins”

GEMS / PLUGINSИнтересно, полезно, весело

Page 2: RubyBarCamp “Полезные gems и plugins”

Что такое джемс?

RubyGems (rubygems.org) — пакетный менеджер для руби

Единый формат распространения отдельных программ и библиотек

Программа для установки библиотек (джемс)

Сервер для распространения джемс

Page 3: RubyBarCamp “Полезные gems и plugins”

Преимущества джемс

require ‘rubygems’require ‘gemname’

sudo gem update

Отсутствие централизации

Стандартный формат: 8300 джемс на Rubyforge, 7400 джемс на Github

Page 4: RubyBarCamp “Полезные gems и plugins”

Github

125000 пользователей

100000 проектов

gists

GitHub Pages

Page 5: RubyBarCamp “Полезные gems и plugins”

restful-authentication (technoweenie)

./script/generate authenticated user sessions

map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’map.login ‘/login’, :controller => ‘session’, :action => ‘new’map.logout ‘/logout’, :controller => ‘session’, :action => ‘destroy’

Page 6: RubyBarCamp “Полезные gems и plugins”

authlogic (binarylogic)

class UserSession < Authlogic::Session::Base # specify configuration here, such as: # logout_on_timeout true # ...many more options in the documentationend

UserSession.create(:login => "john", :password => "my password", :remember_me => true)

session.destroy

Page 7: RubyBarCamp “Полезные gems и plugins”

will_paginate (mislav)

Post.paginate :page => 1, :order => 'created_at DESC'

@posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'

<%= will_paginate @posts %>

Page 8: RubyBarCamp “Полезные gems и plugins”

paperclip (thoughtbot)

class User < ActiveRecord::Base has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }end

<%= image_tag @user.avatar.url %><%= image_tag @user.avatar.url(:medium) %><%= image_tag @user.avatar.url(:thumb) %>

Page 9: RubyBarCamp “Полезные gems и plugins”

cucumber (aslakhellesoy)

Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers

Scenario: Add two numbers Given I visit the calculator page And I fill in '50' for 'first' And I fill in '70' for 'second' When I press 'Add' Then I should see 'Answer: 120'

Page 10: RubyBarCamp “Полезные gems и plugins”

cucumber (cont’d)

Given /^I visit the calculator page$/ do  visit '/add'end

Given /^I fill in '(.*)' for '(.*)'$/ do |value, field|  fill_in(field, :with => value)end

When /^I press '(.*)'$/ do |name|  click_button(name)end

Then /^I should see '(.*)'$/ do |text|  response_body.should contain(/#{text}/m)end 

Page 11: RubyBarCamp “Полезные gems и plugins”

attachment_fu (technoweenie)

has_attachment :size => 1.megabyte..2.megabyteshas_attachment :content_type => 'application/pdf'has_attachment :store => :s3, :cloudfront => true

attachment_obj.public_filename #=> /attachments/2/file.jpgattachment_obj.public_filename(:thumb) #=> /attachments/2/file_thumb.jpg

Page 12: RubyBarCamp “Полезные gems и plugins”

webrat (brynary)

visit home_pathclick_link "Sign up"fill_in "Email", :with => "[email protected]"select "Free account"click_button "Register"

Page 13: RubyBarCamp “Полезные gems и plugins”

bort (fudgestudios)

default css

rm rails.png/index.html

page title helper

application layout

filtering password /password_confirmation

database for sessions

capistrano for git/passenger

plugins (RESTful authentication, role requirement, Open ID authentication, will_paginate, rspec/rspec-rails, exception notifier, asset packager)

Page 14: RubyBarCamp “Полезные gems и plugins”

whenever (javan)

wheneverize .

every 3.hours do runner "MyModel.some_process" rake "my:rake:task"end

every 1.day, :at => '4:30 am' do command "/usr/bin/my_great_command"end

whenever --update-crontab

Page 15: RubyBarCamp “Полезные gems и plugins”

formtastic (justinfrench)

<% semantic_form_for @article do |form| %> <% form.inputs :name => "Basic" do %> <%= form.input :title %> <%= form.input :publication_state, :as => :radio %> <%= form.input :allow_comments, :label => "Allow commenting on this article" %> <% end %>`

<% form.inputs :name => "Advanced" do %> <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %> <% end %>

<% form.inputs :name => "Author", :for => :author do |author_form| %> <%= author_form.input :first_name %> <%= author_form.input :last_name %> <% end %>

<% form.buttons do %> <%= form.commit_button %> <% end %><% end %>

Page 16: RubyBarCamp “Полезные gems и plugins”

delayed_job (tobi)

create_table :delayed_jobs, :force => true do |table| table.integer :priority, :default => 0 #Allows some jobs to jump to the front of the queue

table.integer :attempts, :default => 0 #Provides for retries, but still fail eventually.

table.text :handler #YAML-encoded string of the object that will do work

table.string :last_error #reason for last failure (See Note below)

table.datetime :run_at #When to run. Could be Time.now for immediately, or sometime in the future. table.datetime :locked_at #Set when a client is working on this object

table.datetime :failed_at #Set when all retries have failed (actually, by default, the record is

deleted instead)

table.string :locked_by #Who is working on this object (if locked)

table.timestamps end

MyJob#perform

Page 17: RubyBarCamp “Полезные gems и plugins”

haml (Hampton Caitlin)

%ul %li Salt %li Pepper

%p Date/Time: - now = DateTime.now %strong= now - if now > DateTime.parse("December 31, 2006") = "Happy new " + "year!"

!main_bg= #46ar12!main_width= 40em

#main background-color = !main_bg width = !main_width .sidebar background-color = !main_bg + #333333 width = !main_width - 25em

Page 18: RubyBarCamp “Полезные gems и plugins”

searchlogic (binarylogic)

User.username_equals("bjohnson")User.username_does_not_equal("bjohnson")User.username_begins_with("bjohnson")User.username_not_begin_with("bjohnson")User.username_like("bjohnson")User.username_ends_with("bjohnson")User.age_greater_than(20)User.age_greater_than_or_equal_to(20)User.username_nullUser.username_not_nullUser.username_blank

Page 19: RubyBarCamp “Полезные gems и plugins”

searchlogic (cont’d)

User.username_eq(10) # equalsUser.id_lt(10) # less thanUser.id_lte(10) # less than or equal toUser.id_gt(10) # greater thanUser.id_gte(10) # greater than or equal toUser.orders_total_greater_than(20)User.orders_line_items_price_greater_than(20)User.ascend_by_order_totalUser.descend_by_orders_line_items_priceUser.username_like_all("bjohnson", "thunt") #will return any users that have all of the strings in their username

User.username_like_any(["bjohnson", "thunt"]) #also accepts an array

User.username_or_first_name_like("ben")User.id_or_age_lt_or_username_or_first_name_begins_with(10)search = User.search(:username_like => "bjohnson", :age_less_than => 20)User.named_scope :four_year_olds, :conditions => {:age => 4}User.search(:four_year_olds => true, :username_like => "bjohnson")User.username_like("bjohnson").age_less_than(20).paginate(:page => params[:page])User.search(:username_like => "bjohnson", :age_less_than => 20).paginate(:page => params[:page])User.searchlogic

Page 20: RubyBarCamp “Полезные gems и plugins”

Автора ÿбер-джемсовTechnoweenie — Рик Олсон, ENTP

Binarylogic — Бен Джонсон, Binary Logic

Mislav — Мислав Марохнич, Uniqpath

Aslakhellesoy — Аслак Хеллесёй, BEKK Consulting

Brynary — Брайан Хелмкамп, weplay

Fudgestudios — Фил Джеффс, fudgestudios

Javan — Джаван Махмали, Inkling Markets

Justinfrench — Джастин Френч, Indent

Tobi — Тобиас Лютке, JadedPixel

hampton — Хэмптон Кейтлин

Page 21: RubyBarCamp “Полезные gems и plugins”

Спасибо!

[email protected]

@apostlion