Class: JekyllTrello

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_trello.rb

Class Method Summary collapse

Class Method Details

.bundle_installObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/jekyll_trello.rb', line 163

def self.bundle_install
  gemfile_path = "Gemfile"

  unless File.exist?(gemfile_path)
    gemfile_content="    source 'https://rubygems.org'\n\n    gem 'ruby-trello'\n    gem 'dotenv'\n    GEMFILE\n    File.write(gemfile_path, gemfile_content)\n  else\n    gemfile_content = File.read(gemfile_path)\n\n    unless gemfile_content.include?(\"dotenv\")\n      gemfile_content +=\"\\ngem 'dotenv' \\n\"\n    end\n    unless gemfile_content.include?(\"ruby-trello\")\n      gemfile_content +=\"\\ngem 'ruby-trello' \\n\"\n    end\n\n    File.write(gemfile_path,gemfile_content)\n    puts \"Gems 'ruby-trello' and 'dotenv' added to Gemfile.\"\n\n  end\n  system(\"bundle install\")\n  puts \"Gems installed successfully!\"\nend\n"

.creator(idList) ⇒ Object



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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jekyll_trello.rb', line 2

def self.creator(idList)
  bundle_install
  github
  Dir.mkdir("_plugins") unless Dir.exist?("_plugins")
  content = "    require 'dotenv/load'\n    require 'trello'\n    # require 'pry'\n    module Jekyll\n      class ContentCreatorGenerator < Generator\n        safe true\n        ACCEPTED_COLOR = \"green\"\n\n        def setup\n          @trello_api_key = ENV['TRELLO_API_KEY']\n          @trello_token = ENV['TRELLO_TOKEN']\n\n          Trello.configure do |config|\n            config.developer_public_key = @trello_api_key\n            config.member_token = @trello_token\n          end\n        end\n\n        def generate(site)\n          setup\n          existing_posts = Dir.glob(\"./_posts/*\").map { |f| File.basename(f) }\n\n          cards = Trello::List.find(\"\#{idList}\").cards\n          cards.each do |card|\n            labels = card.labels.map { |label| label.color }\n            next unless labels.include?(ACCEPTED_COLOR)\n            due_on = card.due&.to_date.to_s \n            slug = card.name.split.join(\"-\").downcase\n            created_on = DateTime.strptime(card.id[0..7].to_i(16).to_s, '%s').to_date.to_s\n            article_date = due_on.empty? ? created_on : due_on\n            content = \"\"\"---\n    layout: post\n    title: \\\#{card.name}\n    date: \\\#{article_date}\n    permalink: \\\#{slug}\n    ---\n\n            \\\#{card.desc}\n            \"\"\"\n            file_path = \"./_posts/\\\#{article_date}-\\\#{slug}.md\" \n            if !File.exist?(file_path) || File.read(file_path) != content\n              File.open(file_path, \"w+\") { |f| f.write(content) }\n            end  \n            existing_posts.delete(\"\\\#{article_date}-\\\#{slug}.md\")\n          end\n\n          existing_posts.each do |stale_post|\n            file_path = \"./_posts/\\\#{stale_post}\"\n            File.delete(file_path) if File.exist?(file_path)\n          end\n        end\n      end\n    end\n  RUBY\n\n  file_path = \"_plugins/creater.rb\"\n  File.write(file_path, content)\n  puts \"File '\#{file_path}' has been created successfully!\"\nend\n"

.env_gitignoreObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/jekyll_trello.rb', line 192

def self.env_gitignore
  gitignore_path=".gitignore"

  if File.exist?(gitignore_path)
    gitignore_content = File.read(gitignore_path)

    unless gitignore_content.include?(".env")
      File.open(gitignore_path, "a") do |file|
        file.puts(".env")  
      end
      puts ".env has been added to .gitignore"
    else
      puts ".env is already in .gitignore"
    end
  else
    puts "No .gitignore file found. Please create one first."
  end

end

.githubObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/jekyll_trello.rb', line 67

def self.github
  ruby_version
  scripts
  env_gitignore
  content= "name: Build blogs from Trello Card\n\non:\npush:\n  branches:\n    - gh-pages\nschedule:\n  - cron: '0 0 * * *'\nworkflow_dispatch:\n\njobs:\nbuild-and-deploy:\n  name: Build and commit on same branch\n  runs-on: ubuntu-latest\n  steps:\n    - name: Checkout source code\n      uses: actions/checkout@v2\n    \n    - name: create .env file\n      run: echo \"${{ secrets.DOT_ENV }}\" > .env\n    \n    - name: Setup ruby \n      run: echo \"::set-output name=RUBY_VERSION::$(cat .ruby-version)\"\n      id: rbenv\n    \n    - name: Use Ruby ${{ steps.rbenv.outputs.RUBY_VERSION }}\n      uses: ruby/setup-ruby@v1\n    \n    - name: Use cache gems\n      uses: actions/cache@v1\n      with:\n        path: vendor/bundle\n        key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}\n        restore-keys: |\n          ${{ runner.os }}-gem-\n\n    - name: bundle install\n      run: |\n        gem install bundler -v 2.4.22\n        bundle install --jobs 4 --retry 3 --path vendor/bundle\n    \n    - name: rm posts\n      run: |\n        cp ./scripts/rmposts.sh _posts/rmposts.sh\n        chmod +x _posts/rmposts.sh\n        cd _posts\n        sh rmposts.sh\n        rm rmposts.sh\n        cd ..\n    - name: Build posts\n      run: |\n        bundle exec jekyll build\n        \n    - uses: EndBug/add-and-commit@v7\n      with:\n        add: '*.md'\n        author_name: Habi Pyatha\n        branch: gh-pages\n        message: 'auto commit'\n  RUBY\n  Dir.mkdir(\".github\") unless Dir.exist?(\".github\")\n  Dir.mkdir(\".github/workflows\") unless Dir.exist?(\".github/workflows\")\n  file_path = \".github/workflows/build-block.yml\"\n  File.write(file_path, content)\n  puts \"File '\#{file_path}' has been created successfully!\"\n\nend\n"

.ruby_versionObject



140
141
142
143
144
# File 'lib/jekyll_trello.rb', line 140

def self.ruby_version
  file_path = ".ruby-version"
  File.write(file_path, "3.3.4")
  puts "File '#{file_path}' has been created successfully!"
end

.scriptsObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/jekyll_trello.rb', line 146

def self.scripts
  content= "counts= `ls -1 *.md 2>/dev/null | wc-1`\nif [ $count != 0]\nthen \necho true\necho \"Removing all md files\"\nrm *.md\nfi\n  RUBY\n  Dir.mkdir(\"scripts\") unless Dir.exist?(\"scripts\")\n  file_path = \"scripts/rmposts.sh\"\n  File.write(file_path, content)\n  puts \"File '\#{file_path}' has been created successfully!\"\n\nend\n"