Use Padrino and sprockets with sprockets-helpers

Thanks to @arthur_chiu and his post on how to integrate sprockets in Padrino with sprockets-helpers, i’ve create my version :D:D:D:D

1) Create padrino-sprockets in config/sprockets.rb

module Padrino::Sprockets
  def self.registered(base)
    base.set :sprockets, ::Sprockets::Environment.new(Padrino.root)
 
    # Add folder
    base.sprockets.append_path 'assets/javascripts'
    base.sprockets.append_path 'assets/stylesheets'
    base.sprockets.append_path 'assets/images'
    base.set :digest_assets, true
 
    # compress file
    if PADRINO_ENV == 'development'
      base.sprockets.js_compressor = Uglifier.new(mangle: true)
      base.sprockets.css_compressor = YUI::CssCompressor.new
    end
 
    # sprockets-helpers
    base.helpers Sprockets::Helpers
    # We can configure `sprockets-helpers` to find the correct assets for us.
    Sprockets::Helpers.configure do |config|
      manifest_path      = File.join(Padrino.root,'public','assets','manifest.json')
      config.environment = base.sprockets
      config.prefix      = '/assets'
      config.manifest    = Sprockets::Manifest.new(base.sprockets, manifest_path)
      config.digest      = true
      config.public_path = base.public_folder
    end
 
    # call sprockets πŸ˜€
    if PADRINO_ENV == 'development'
      base.get '/assets/*splat' do
        env['PATH_INFO'].gsub!(%r{A/?assets}, '')
        settings.sprockets.call(env)
      end
    end
  end
end

In this file you need add all your asset’s folder..

2) Load this file at startup application:
config/boot.rb

# after this line
Bundler.require(:default, PADRINO_ENV)
 
# add this
require Padrino.root('config/sprockets')

3) register Padrino::Sprockets in your application

Module Foo
  class App < Padrino::Application
   register Padrino::Sprockets
 
  end
end

4) Use js,css sprockets version in you layout, es:

layout.slim

link href= stylesheet_path('app') media="screen" type="text/css" rel="stylesheet"

instead

= stylesheet_link_tag :app

5) Use Rakefile to create asstes to pre-compilation :D:D

PADRINO_ENV  = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development'  unless defined?(PADRINO_ENV)
 
require 'bundler/setup'
require 'padrino-core/cli/rake'
 
 
require 'sprockets/../rake/sprocketstask'
 
 Bundler.require(PADRINO_ENV)
require File.expand_path("../config/boot.rb", __FILE__)
 
PadrinoTasks.use(:database)
PadrinoTasks.use(:minirecord)
PadrinoTasks.init
 
# Use fake application 
module FakeSprock
  class App < Padrino::Application
    register Padrino::Sprockets
  end
end
 
SPROCKETS = FakeSprock::App.sprockets
 
# or your real app name
# SPROCKETS = RealAppName::App.sprockets
 
Rake::SprocketsTask.new do |t|
  manifest_path = File.join(Padrino.root,'public','assets')
  t.environment = SPROCKETS
  t.output      = File.join(Padrino.root,'public','assets')
  t.manifest    = Sprockets::Manifest.new(SPROCKETS, manifest_path)
  t.assets      = %w[app.js app.css *.png *.gif *.jpg]
end

and call it with

rake assets

To conitnue use stylesheet_link_tag and javascript_include_tag, need to close this issue

Thanks again at @padrino-core.
Special tanks:
DAddYE
@arthur_chiu

Padrino 0.11.0 Released – Padrino Lives!

The Padrino team is very pleased to finally be able to announce the 0.11.0 release of the Padrino Framework! We have been working on this release for almost a year now and we have had dozens of contributors helping us stabilize Padrino. We know our release cycle got out whack and this version took too long to release. We all take accountability for that and will work to pick up release momentum and release patch and minor versions more often.

Since our 0.10.7 release, development on Padrino has been moving forward very actively and as such this is probably our biggest release in terms of code modified and issues resolved that we have had in years. We are very proud of this release which includes several major improvements:

1) Totally Redesigned Admin
2) New brand identity on the way
3) Upgraded Sinatra and http_router
4) CSRF Form Protection
5) ActiveSupport::SafeBuffer
6) New Rakefile format
7) Gemified Apps
8) Performance Tools
9) App Namespacing
10) Project Modules
11) Optimized Reloader

http://www.padrinorb.com/blog/padrino-0-11-0-released-padrino-lives

Usage ImageSorcery with CarrierWave by gem

CarrierWave::ImageSorcery

https://github.com/WaYdotNET/carrierwave-imagesorcery

Additional processing to use ImageSorcery into CarrierWave.

Installation

Add this line to your application’s Gemfile:

gem 'carrierwave-imagesorcery'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-imagesorcery

Usage

To use those, you should include specified module (ImageSorcery) into your uploader and use processors:

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::ImageSorcery
  .....

end

Method implemented

convert
dimensions
resize_to_limit
resize_to_fit
resize_to_fill
resize_and_pad

Example

class Uploader < CarrierWave::Uploader::Base
##
# Image manipulator library:
include CarrierWave::ImageSorcery

process :resize_and_pad => [900,300,"#ffeecc", 'South']
process :resize_to_fit => [1024, 768]

end

Example custom method

An example to implement custom method

class Uploader < CarrierWave::Uploader::Base
include CarrierWave::ImageSorcery
process :watermark_text

def watermark_text(text = "Β© #{Time.now.year} - Carlo Bertini [WaYdotNET]")
  manipulate! do |img|
    args  = {
      font: 'Helvetica', fill: 'white', stroke: '#00770080',
      gravity: 'South', pointsize: 20, draw: " text 0,0 "#{text}" "
    }
    img.manipulate! args
    img
  end
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am ‘Added some feature’)
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

endorse

WaYdotNET, you can follow me on twitter @WaYdotNET or take a look at my site waydotnet.com

Copyright

Copyright (C) 2012 Carlo Bertini – @WaYdotNET

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the β€œSoftware”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The library is a simple API in Ruby for Microsoft Translator V2

MsTranslate

The library is a simple API in Ruby for Microsoft Translator V2

The Microsoft Translator services can be used in web or client applications to perform language translation operations. The services support users who are not familiar with the default language of a page or application, or those desiring to communicate with people of a different language group.

Installation

Add this line to your application’s Gemfile:

gem 'ms_translate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ms_translate

Usage

first step set your appId

$ MsTranslate::Api.appId = 'MyRealAppId'

traNslate method:

$ MsTranslate::Api.translate('Hello World!)
$ => Ciao, Mondo!

Method not implemented

  1. Microsoft.Translator.AddTranslation Method
  2. Microsoft.Translator.AddTranslationArray Method

Test

You need to insert your appId into

# File 'spec/lib/ms_translate/api_spec.rb'
@api_real =  'INSERT_YOUR_APPID'

Contributing

  1. Fork it
  2. Create your feature branch (
    git checkout -b my-new-feature

    )

  3. Commit your changes (
    git commit -am 'Added some feature'

    )

  4. Push to the branch (
    git push origin my-new-feature

    )

  5. Create new Pull Request

Author

endorse

WaYdotNET, you can follow me on twitter @WaYdotNET or take a look at my site waydotnet.com

Copyright

Copyright (C) 2012 Carlo Bertini – @WaYdotNET

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the β€œSoftware”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Padrino-admin Twitter Bootstrap v2.0 is ready

(Padrino Admin TwitterBootstrap 2.0)

  • Padrino-Modal: rack-flash and delete function into modal πŸ˜€
  • highlights error field
  • tof helper: Automatic replace true or false with relative image (list.slim and list.haml)
  • Breadcrumbs
  • Automatic time_ago_in_words when column model is created_at or updated_at
  • Migrate function for MiniRecord

Padrino-Modal

All result from rack-flash and delete request, now is automatic insert into modal javascript plugin

highlights error field

tof_helper

Automatic replace true or false with relative image (list.slim and list.haml)

Breadcrumbs

Automatic Breadcrumbs system:

time_ago_in_words

Automatic time_ago_in_words when column model is created_at or updated_at

MiniRecord migrate

Migrate function for MiniRecord

Demo:

http://padrino.waydotnet.com/admin
user: test@padrinorb.cpm
password: test

By WaYdotNET

Padrino Admin another new layout (based on Twitter Bootstrap v2.0-wip)

http://glowing-leaf-7114.heroku.com/admin/
user: test@padrinorb.com
pass: test

PLEASE DON’T CHANGE LOGIN/PASSWORD

Additional feature:

  • ✔ Padrino-Modal: rack-flash and delete function into modal πŸ˜€
  • ✔ highlights error field
  • ✔ tof helper: Automatic replace true or false with relative image (list.slim and list.haml)
  • ✔ Breadcrumbs
  • ✔ Automatic time_ago_in_words when column model is created_at or updated_at
  • ✔ Migrate function for MiniRecord

clone my repository and enjoy πŸ˜€

https://github.com/WaYdotNET/padrino-framework

See the code and comment please !!!!

CoffeScript (1.1.1) on Windows: simple method !

CoffeScript (1.1.1) on Windows: simple method !


Inspiration: http://blog.mnasyrov.com/post/2872046541/coffeescript-on-windows-how-to-roast-coffee

To use CoffeScript you need:

  1. Node.js
  2. CoffeeScript
  3. Batch file to run CoffeeScript

 

STEP 1: Node.js

 

I’m very very lazy dev… πŸ˜€
And i don’t recompile NodeJs into Windows….. but I’m using v0.4.7 from http://node-js.prcn.co.cc/ [many thx]
and install into:

D:>cd ToolsNodeJsbin

D:ToolsNodeJsbin>node --version
v0.4.7

 

STEP 2: CoffeeScript

 

Use the last version , grab it from https://github.com/jashkenas/coffee-script
and install into:

D:ToolsCoffeeScript

Check version

D:ToolsNodeJsbinnode /cygdrive/D/Tools/CoffeeScript/bin/coffee --version
CoffeeScript version 1.1.1

Node.js need unix-path


Step 3: Batch file

 

I don’t know well bat syntax, and my code is VERY VERY ugly.. but it works πŸ˜›

 

@echo off

:: Directories of the tools
SET coffeeDir=D:ToolsCoffeescriptbin
SET nodeDir=D:ToolsNodeJsbin

:: var
SET a=%1
SET b=%2
SET c=%3
SET d=%4
SET e=%5
SET f=%6
SET g=%7
SET h=%8
SET i=%9

:: Check input value if exist and if it's option or file

:A
IF "%a%"=="" GOTO :B
IF "%a:~0,1%"=="-" GOTO :B
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %1') DO SET a=%%o
:B
IF "%b%"=="" GOTO :C
IF "%b:~0,1%"=="-" GOTO :C
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %2') DO SET b=%%o
:C
IF "%c%"=="" GOTO πŸ˜€
IF "%c:~0,1%"=="-" GOTO πŸ˜€
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %3') DO SET c=%%o
πŸ˜€
IF "%d%"=="" GOTO :E
IF "%d:~0,1%"=="-" GOTO :E
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %4') DO SET d=%%o
:E
IF "%e%"=="" GOTO :F
IF "%e:~0,1%"=="-" GOTO :F
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %5') DO SET e=%%o
:F
IF "%f%"=="" GOTO :G
IF "%f:~0,1%"=="-" GOTO :G
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %6') DO SET f=%%o
:G
IF "%g%"=="" GOTO :H
IF "%g:~0,1%"=="-" GOTO :H
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %7') DO SET g=%%o
:H
IF "%h%"=="" GOTO :I
IF "%h:~0,1%"=="-" GOTO :I
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %8') DO SET h=%%o
:I
IF "%i%"=="" GOTO :COMMAND
IF "%i:~0,1%"=="-" GOTO :COMMAND
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %9') DO SET i=%%o

:COMMAND
FOR /f %%o IN ('%nodeDir%/cygpath.exe -a -u %coffeeDir%') DO SET p=%%o
%nodeDir%node %p%/coffee %a% %b% %c% %d% %e% %f% %g% %h% %i%

 

set the PATH environment variable contains a path to coffee.bat

the name of the file is very important,Β  in my case it works well with coffee-rack

Enjoy

Many thanks to:

Mikhail Nasyrov => http://blog.mnasyrov.com/post/2872046541/coffeescript-on-windows-how-to-roast-coffee
Node.js self-contained Windows binaries => http://node-js.prcn.co.cc/index.html
Jeremy Ashkenas => http://jashkenas.github.com/coffee-script/

LAZY Agnostic Application Generators (padrino-lazy)

Overview

Through padrino-lazy, we can include some common properties shared between the model object used a base model object

Padrino is very good framework, and almost follows the DRY principle (Don’t Repeat Yourself) When we need to have some common properties shared between the model object of our ORM, using the generator padrino-gen, We can only include these properties in each model to generate.

I hope this idea will be included in Padrino Framework.
Principle / Step

  1. generate a model
  2. convert the model into base model ( move this model into lib/ folder)
  3. save config file with model base’s list
  4. generate a model from base model
  5. generate a migration file

Usage

Step 1-2-3

$ padrino-lazy base --c config_file --b base_model_name --f field_to_create

Step 4-5

$ padrino-lazy model --c config_file --b base_model_name --f field_to_create --m model_name

Install

gem install padrino-lazy --pre

Example

$ padrino-lazy base --c config --b BaseModel --f "create_at:datetime is_active:boolean"

now we have

lib/base_model.rb class BaseModel


include DataMapper::Resource

  # property ,
  property :id, Serial
  property :create_at, DateTime
  property :is_active, Boolean

end

config/config.yml


---
- base: BaseModel
fields: create_at:datetime is_active:boolean
$ padrino-lazy model --c config --b BaseModel --f "name:string have_children:boolean born:date foo:integer"  --m User

app/models/user.rb

class User <  BaseModel

  # property ,
  property :name, String
  property :have_children, Boolean
  property :born, Date
  property :foo, Integer
end

db/migrate/001_create_users.rb


migration 1, :create_users do
  up do
    create_table :users do
      column :id, Integer, :serial =&gt; true
      column :name, String
      column :have_children, Boolean
      column :born, Date
      column :foo, Integer
    end
  end

  down do
    drop_table :users
    end
  end

db/migrate/002_add_basic_model_to_user.rb


migration 2, :add_basic_model_to_user do
  up do
    modify_table :users do
      add_column :name, String
      add_column :have_children, Boolean
      add_column :born, Date
      add_column :foo, Integer
  end
end

down do
modify_table :users do
drop_column :name
drop_column :have_children
drop_column :born
drop_column :foo
end
end
end

Known issue

  • VERY VERY alpha code !! (thanks to my pig/lazy side πŸ˜€ )
  • β€”f options need dobule quote around fields
  • β€”b write in CamelCase
  • TESTING only with datamapper and activerecord into linux machine

TODO:

  • Test all code !
  • Use Padrino::Generators instead of Commander
  • Default config file name (very lazy πŸ˜› )

THANK

  • Team Padrino
  • DaddYE
  • Piedinodifata

CODE
https://github.com/WaYdotNET/padrino-lazy