Skip to content

Commit

Permalink
Finish fixed to syntax highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
leylaKapi committed May 19, 2014
1 parent 09f4f84 commit 2f7792c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,76 @@ tags: paperclip

Öncelikle paperclip geminin processorları aradığı

lib/paperclip_processors
```
lib/paperclip_processors
```


klasörünün içine watermark.rb dosyamızı oluşturup

```
module Paperclip
class Watermark < Thumbnail
# Handles watermarking of images that are uploaded.
attr_accessor :format, :whiny, :watermark_path, :position

def initialize file, options = {}, attachment = nil
super
@file = file
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
@watermark_path = options[:watermark_path]
@position = options[:watermark_position].nil? ? "SouthEast" : options[:watermark_position]

@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end

# Performs the conversion of the +file+ into a watermark. Returns the Tempfile
# that contains the new image.
def make
return @file unless watermark_path

dst = Tempfile.new([@basename, @format].compact.join("."))
dst.binmode

command = "composite"
params = "-gravity #{@position} #{watermark_path} #{fromfile} #{tofile(dst)}"

begin
success = Paperclip.run(command, params)
rescue PaperclipCommandLineError
raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
end

dst
end

def fromfile
"\"#{ File.expand_path(@file.path) }[0]\""
end

def tofile(destination)
"\"#{ File.expand_path(destination.path) }[0]\""
end
end
end
```


şeklinde watermark classımızı ekliyoruz.

Ardından ilgili model dosyamızda

```
has_attached_file :photo,
processors: [:thumbnail, :watermark],
styles: {
zoom: { geometry: '1024x576#', watermark_path: "#{Rails.root}/app/assets/images/watermarks/watermark_zoom.png"},
main: { geometry: '770x520#', watermark_path: "#{Rails.root}/app/assets/images/watermarks/watermark_main.png"}
}

```

şeklinde eklediğimiz resimler için kullanılacak processorlerı tanımlıyoruz, thumbnail resimlerin boyutunu düzenlemek için paperclipte tanımlanmış processor classıdır eklenmediği sürece resim boyutlandırması yapılmaz. Ardından farklı boyutlar için yeniden boyutlandırma için geometry ve watermark olarak eklenecek resmimizin path'ini veriyoruz.

Bu işlemlerden sonra eklenecek her resime watermark'ınız eklenecektir.

Eğer daha önce upload ettiğiniz resimlere de watermark'ınızın eklenmesini istiyorsanız.

rake paperclip:refresh class=Product
```
rake paperclip:refresh class=Product
```


rake'ini çalıştırmanız yeterlidir.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@ First off, you must include JS and CSS files of Medium Editor. It doesn’t matt

I’m using it in a form partial (one of my current projects).

```
=stylesheet_link_tag 'medium-editor.css'
=javascript_include_tag 'medium-editor'

= form_for @post do |f|
= f.hidden_field :body, html: { id: "body" }
.editable { data: { field: { id: "body" } } }
= f.submit

=javascript_include_tag 'input-field'
```



Normally you can just add ".editable" class on any element you like but you can't do it for an input field. What I've done is, I just created my input field as hidden and a editable div with ***data-field-id*** is "body".

Normally you can just add `.editable` class on any element you like but you can't do it for an input field. What I've done is, I just created my input field as hidden and a editable div with ***data-field-id*** is `body.

IDs of input field and editable field must be same, so we can create a polymorphic system for synchronization. Let's get to the ***input-field.js*** file.

```
var editor = new MediumEditor('.editable');

$('.editable').bind('input propertychange', function() {
$("#post_" + $(this).attr("data-field-id")).val($(this).html());
});
```


When you create a MediumEditor object with '.editable' class, all elements (except input fields) with '.editable' class will turn into Medium Editor.
When you create a MediumEditor object with `.editable class, all elements (except input fields) with `.editable` class will turn into Medium Editor.

Real magic we'll use is "bind" method of HTML elements. (Also I must warn you that you must include standard jQuery libraries). When a editable class element is changed, inner code of bind method will run. This way we'll get the editable element's ***data-field-id*** and concatenate it with "#post_" string.
Real magic we'll use is `bind` method of HTML elements. (Also I must warn you that you must include standard jQuery libraries). When a editable class element is changed, inner code of bind method will run. This way we'll get the editable element's ***data-field-id*** and concatenate it with `#post_` string.

Then we set the value of "#post_element" with editable class element's inner HTML. If you keep the names of hidden element and editable section same, you get a polymorphic synchronization. So you can use multiple Medium Editor input fields.
Then we set the value of `#post_element` with editable class element's inner HTML. If you keep the names of hidden element and editable section same, you get a polymorphic synchronization. So you can use multiple Medium Editor input fields.

28 changes: 19 additions & 9 deletions source/posts/2014-03-03-sass-nedir-ozellikleri-nelerdir.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,67 +63,77 @@ Css çıktısı:

**Partials ve @import:** Kodlarımızı bölümleyip istediğimiz yerde import edebiliyoruz.

/* _reset.sass */
```sass
/* _reset.sass */
body
margin: 0
padding: 0
```


Bu dosyayı asıl stil dosyamıza dahil edelim.

/* base.sass */
```sass
/* base.sass */
@import 'reset'
```


**Mixins:** bu özellik sayesinde css3 ün hayatımızı zor bir yoldan kolaylaştıran özelliklerini sıkılmadan uygulayabileceğiz.

```sass
@mixin border-radius($radius)
-webkit-border-radius: $radius
-moz-border-radius: $radius
-ms-border-radius: $radius
-o-border-radius: $radius
border-radius: $radius
```


Mixin'i sass'da çağırıyoruz.

```sass
.box
@include border-radius(10px)


```
Bu mixin'inden sonra border-radius kullandığımızda ekstra kodları yazmamıza gerek yok.

**Extend/Inheritance:** class yada id'lerde kullandığımız özellikleri @extend özelliği ile bir sonraki class yada id mizin içinde kullanabiliyoruz.

message class'ı için kodlarımız bunlar.

```sass
.message
border: 1px solid #ccc
padding: 10px
color: #333

```

Şimdide diğer class yada id'mizde bu kodları extend edelim.

```sass
.success
@extend .message
border-color: green

.error
@extend .message
border-color: red

```

**Operators:** css özelliklerini yazarken operatorleri kullanabileceğimizi biliyor muydunuz? :)

```sass
aside
float: right
width: 300px / 960px * 100%

```

Css çıktısı:

```css
aside {
float: right;
width: 31.25%;
}
}
```
2 changes: 1 addition & 1 deletion source/posts/2014-04-22-rails-view-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is our sample haml code block which shows icons and link to videos. As you
There is a `helpers` directory in app folder and we write our custom view helper there.


````
```
app/
assets/
controllers/
Expand Down

0 comments on commit 2f7792c

Please sign in to comment.